Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Infix call syntax for binary functions #8824

Closed
bluss opened this Issue · 8 comments

5 participants

@bluss
Collaborator

Allow calling binary functions infix. Functions and method calls are enclosed by mandatory parantheses, and these obscure the logic of the code when nested.

Methods are already placed neatly (like operators) bewteen two objects (a .eq (b)) but with an infix call we can make this easier to read.

a.and(b.and(c.and(d)))

can be

a `and` b `and` c `and` d

and instead of overloading + for lists we can have

~[1,2,3] `concat` ~[2,3,4]

or a parser can use

AlNum `and` (AlNum `or` Hyphen)

Infix binary functions are simpler and have less drawbacks compared to arbitrary user operators. They are also more flexible than the builtin set of operators (that are limited in number and force call by &T).

@glaebhoerl

For future reference we had some discussion about this on reddit: [link]

The most important point was that backticks are probably not desirable, and a better syntax might be:

a \and b \and c \and d
~[1,2,3] \concat ~[2,3,4]
AlNum \and (AlNum \or Hyphen)
@cartazio

would this have a way of setting fixity / associativity?

@glaebhoerl

Well this whole thing is speculative, so all we have is our ideas and opinions. I think that would introduce usability issues again -- if you're looking at some code using \operators, you wouldn't know how to read it until you looked up all of the relevant fixity and associativity declarations. @cartazio what's a use case where you would want it?

@cartazio

numerical linear algebra code. Probably where I'd be building up an AST model of the "math" then running a version that internally does an inplace update execution using a fixed number of pre allocated array buffers.

@glaebhoerl

Would having to explicitly parenthesize be horrible?

@cartazio

nope, was just asking. I understand that being conservative for near term features is important.

@thehydroimpulse

@brson Any thoughts on this? I'm guessing this would require a proper RFC with the new process, but is this something Rust would be interested in supporting?

@alexcrichton
Owner

Closing, a change such as this should go through the RFC process, both to flesh out and get community feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.