rhombus-prototype icon indicating copy to clipboard operation
rhombus-prototype copied to clipboard

Impossible wish: display( x <= y < z)

Open gus-massa opened this issue 6 years ago • 3 comments

I think this is impossible, and I posted this before as a comment, but I want to post it here in case someone has a idea to make it happen.

With some of the proposal it is possible to write

display(x < y < z)

and it will interpreted as

(display (< x y z))

and the result is a boolean.

I'd like to be able to write

display(x < y <= z)

and also get a boolean as the result.

In Phyton you can write

phyton> print(x < y <= z)

but I suspect they are "cheating", i.e. the internal representation is different from the a naive transformation of the text. I think it is important to not add too many weird transformation be able to write macros without understanding all the details.

One possibility is to redefine < and <= as

(define (< x y) (and x y (old-< x y) y) 
(define (<= x y) (and x y (old-<= x y) y) 

so

display(x < y <= z)

is

(display (<= (< x y) z))

but the result is the number z instead of a boolean.

One solution is to write

    display(x < y <= z && #t)

but the last && #t is not beginners friendly.

gus-massa avatar Sep 04 '19 21:09 gus-massa

I agree that this is very desirable.

jeapostrophe avatar Sep 04 '19 23:09 jeapostrophe

In Phyton you can write

phyton> print(x < y <= z)

but I suspect they are "cheating", i.e. the internal representation is different from the a naive transformation of the text. I think it is important to not add too many weird transformation be able to write macros without understanding all the details.

Reminded me of https://twitter.com/jangle/status/1227721188438421506

'c' in 'cat' == True

in Python expands to

('c' in 'cat') and ('cat' == True)

sorawee avatar Mar 10 '20 19:03 sorawee

In Rebellion I defined compare-infix, which you can use like this:

(require rebellion/base/comparator)

(compare-infix real<=> 1 < 3 <= 5)  ; returns #true

jackfirth avatar Oct 28 '21 07:10 jackfirth