[Python-3000] sets in P3K?
Guido van Rossum
guido at python.org
Wed May 3 18:57:42 CEST 2006
On 5/2/06, Neal Norwitz <nnorwitz at gmail.com> wrote:
> On 5/2/06, Raymond Hettinger <rhettinger at ewtllc.com> wrote:
> >
> > I think Guido had the best solution. Use set() for empty sets, use {}
> > for empty dicts, use {genexp} for set comprehensions/displays, use
> > {1,2,3} for explicit set literals, and use {k1:v1, k2:v2} for dict
> > literals. We can always add {/} later if demand exceeds distaste.
>
> Presumably {1, 2, 3: 4} would yield a syntax error?
Of course. I am thinking of the syntax as a kind of railroad diagram
for a finite state machine; from '{' you can go directly to '}' or to
EXPR; after that you can see ':' or ',' or '}'; if you see ':' from
then on you are constrained to EXPR:EXPR pairs; if you see '.' you are
constrained to single EXPRs alternating with commas. Taking the
current Grammar file we could do this:
atom: ... | '{' [dictorsetmaker] '}'
dictorsetmaker: test ':' test (',' test ':' test)* [','] | test
(',' test)* [',']
The apparent ambiguity between the two alternatives in the second rule
doesn't matter; our parser generator takes all the alternatives for a
rule together and turns them into a finite state machine as described
above.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list