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

Have <, > and others take 0 or more arguments

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

  • Have <, > and others take 0 or more arguments (returning #t for the 0 and 1 argument cases). This would allow applying them to lists without fear, which would allow patterns like (define (sorted? l) (apply < l))

Extracted from the old racket2 wiki. #33

I think this can be merged to racket1.

gus-massa avatar Jul 21 '19 18:07 gus-massa

This would definitely conflict with pushing racket2 in the infix direction, where these functions would likely become binary infix operators instead of variable-arity functions.

jackfirth avatar Jul 22 '19 07:07 jackfirth

Adding a 0-argument case wouldn't increase the conflict, given that that they already take 1 or more. There ought to be a non-infix way to use operators like <, +, etc.

rmculpepper avatar Jul 22 '19 09:07 rmculpepper

Should the variable-arity way use the same names? I personally don't think so, because (to non-racketeers) the symbols are so strongly associated with their infix notation. And that way I wouldn't have to deal with the confusion of reading prefix < / >, which consistently trips me up and causes bugs when I pick the wrong one or put the arguments in the wrong order.

jackfirth avatar Jul 23 '19 06:07 jackfirth

For one order I was choosing names for recently, I tried the naming convention [type]-descends? and [type]-ancestor/c instead of [type]<? and [type]</c, and I've been finding it just as confusing. I think this is largely just another poor choice of name: Ancestors come before their descendants chronologically, and the set of values that satisfies [type]-ancestor/c increases in size as the argument is changed to a descendant of itself, but the legacy of object-oriented inheritance hierarchies makes it really tempting to think of a descendant as a subset of its ancestor instead, and this combination of connotations kept messing me up.

For the ordering of real numbers, I usually put my expressions in the order of the number line, so I almost always prefer < or <= rather than > or >= no matter what language I'm in. That makes it fairly easy to read < and <= expressions even in prefix notation, because the only attention I even pay to the operator is to make sure it's pointing the way I expect. :-p

Nevertheless, I do internally pronounce (< 3 x) the same way as (less-than-three? x), which of course has the opposite meaning, and it can be confusing.

So orderings are one place I would find it much more readable to have expressions like (compares? 0 <= i < j < n) and perhaps (compares/c 0 <= _ < n). To make them extra confusion-resistant, perhaps <= and < shouldn't even be functions, just a special type of value (or syntax) that can be passed to these compares? and compares/c operations.

I think I've heard of people implementing this compares? operation before a few times, but if there's one that's common for Racket programmers, I don't know quite what name to look it up by.

rocketnia avatar Jul 23 '19 19:07 rocketnia

Also =. It would be nice to be able to write:

(define (all-same? xs) (apply = xs))

sorawee avatar Jan 06 '20 22:01 sorawee