[Python-3000] Set literals

Georg Brandl g.brandl at gmx.net
Mon Aug 28 22:32:53 CEST 2006


Guido van Rossum wrote:

>> > However you might be able to just cleanup the grammar so they are
>> > identical, that would be simpler I suspect.
>>
>> Looking at the grammar, there's only testlist_safe left to kill, in
>> favor of or_test like in generator expressions. The old_ rules are still
>> needed.
> 
> Hm, it's been so long... Why?

In listcomps/genexps, old_test and old_lambdef do not allow conditional
expressions in order to avoid confusion with the loop's "if".

>> Hm. Is the precedence in
>>
>> x = lambda: 1 if 0 else 2
>>
>> really obvious?
> 
> Yes if you think about how you would use it. Conditionally returning a
> lambda or something else is kind of rare. A lambda using a condition
> is kind of useful. :-)

Okay, that makes sense.

>> >> * list comprehensions are special-cased because of the LIST_APPEND opcode.
>> >>    If there isn't going to be a special-cased SET_ADD, it's probably the
>> >>    easiest thing to transform {x for x in a} into set(x for x in a) in the
>> >>    AST step, with "set" of course always being the builtin set.
>> >
>> > Right. That might actually become a prototype for how to the list
>> > translation as well.
>>
>> Would this need a new opcode, or should generators be special-cased by
>> BUILD_SET?
> 
> Can't remember what BUILD_SET is.

Sorry... it's the newly introduced opcode that creates a new set.

Georg



More information about the Python-3000 mailing list