Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have <, > and others take 0 or more arguments #53

Open
gus-massa opened this issue Jul 21, 2019 · 5 comments
Open

Have <, > and others take 0 or more arguments #53

gus-massa opened this issue Jul 21, 2019 · 5 comments

Comments

@gus-massa
Copy link

  • 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.

@jackfirth
Copy link
Sponsor Collaborator

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.

@rmculpepper
Copy link

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.

@jackfirth
Copy link
Sponsor Collaborator

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.

@rocketnia
Copy link

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.

@sorawee
Copy link
Contributor

sorawee commented Jan 6, 2020

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants