[Python-ideas] a in x or in y

Andrew Barnert abarnert at yahoo.com
Fri Feb 14 12:24:10 CET 2014


On Feb 13, 2014, at 13:20, Haoyi Li <haoyi.sg at gmail.com> wrote:

> Ah, I did not think about the laziness. That indeed is a pain since we can't create our own custom lazy operators/methods. 
> 
> I would say the correct answer is that we should let people define their own lazy operators, and then define or_in or whatever as a lazy operator/method, but I'm sure others would disagree.

Well, first you need to come up with a way to allow people to define new operators in the first place. 

Because the parser can't know what you're going to define at runtime, you can't really do fancy things like specifying precedence or association direction, and they all have to fit some easily detectable pattern. 

So, let's pick a straw man: a `foo` b always means foo(a, b), and has higher precedence than all other binary operators, and left associates. As long as foo has to be an identifier, not an arbitrary expression, this would be pretty simple to add to the grammar.

To add short circuiting, just do this: a ``foo`` b is the same thing as foo(lambda: a, lambda: b). It has the same precedence as single-backtick operators and left associates.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140214/0a6fdeb7/attachment.html>


More information about the Python-ideas mailing list