[Python-3000] Set literals - another try

Nick Coghlan ncoghlan at gmail.com
Wed Aug 9 12:17:25 CEST 2006


Collin Winter wrote:
> On 8/8/06, Josiah Carlson <jcarlson at uci.edu> wrote:
>> I personally don't see much of a use for set literals, considering that
>> there is a non-ambiguous spelling of it currently; set(...), whose only
>> cost above and beyond that of a set literal is a global name lookup.

> I thought one of the main arguments in favor of set literals is that a
> literal form would allow the compiler to perform optimisations that
> the set(...) spelling doesn't allow.

A different way to enable that would be to include a set of non-keyword names 
(a subset of the default builtin namespace) in the language definition that 
the compiler is explicitly permitted to treat as constants if they are not 
otherwise defined in the current lexical scope.

Then constant-folding could turn "len('abcde')" into 5, and "str(3+2)" into 
'5' and "set((1, 2, 3))" into the corresponding set object.

The only thing that would break is hacks like poking an alternate 
implementation of str or set or len into the global namespace from somewhere 
outside the module.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list