[Python-3000] Set literals - another try
jcarlson at uci.edu
Tue Aug 8 19:36:40 CEST 2006
Talin <talin at acm.org> wrote:
> Part 1: The concrete proposal part.
> I noticed that a lot of folks seemed to like the idea of making the
> empty set resemble the greek letter Phi, using a combination of
> parentheses and the vertical bar or forward slash character.
> So lets expand on this: slice Phi in half and say that (| and |) are
> delimiters for a set literal, as follows:
> (|) # Empty set
> (|a|) # Set with 1 item
> (|a,b|) # Set with 2 items
> The advantage of this proposal is that it maintains visual consistency
> between the 0, 1, and N element cases.
That's quite a bit of punctuation to define a set literal. In fact, for
1+ element sets, it's only 1 character shy of the set() punctuation,
while also being more difficult to type on at least US keyboards.
And if I remember my set math correctly, phi wasn't the character
generally used, it was usually a zero with a diagonal cross through it,
making (/) a better empty set literal. But from there, the notation
devolves into a place I don't want to go.
> Part 2: The idle speculation part, not to be considered as a actual
> I've often said that "whenever a programmer has the urge to invent a new
> programming language, that they should lie down on the couch until the
> feeling passes".
Presumably you again don't remember the source of this quote, but it is
> As a thought experiment, I decided to apply this idea to the Python set
> literal case - i.e. if we were going to do a massive "do over" of
> Python, how would we approach the problem of set literals?
> The syntax that comes to mind is something like this:
> a = b|c
The pipe character/bitwise or operator doesn't say to me "make a set".
Knowing what I do about set math, the only literal that really makes
sense to me is:
With the empty set being:
Interstingly enough, the non-empty set case has already been proposed,
and if I remember correctly, was generally liked, except for the
somewhat ambiguity with regards to dictionary literals.
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. It
is 'different' from some other first-class objects (tuple, list,
dictionary, string, unicode, ...), but other first-class objects also
require such spelling: bool, enumerate, iter, len, property, reduce.
Each of which may be used sufficiently often to make sense as having a
syntax for their operations, though perhaps only len having an obvious
syntax of |obj| -> len(obj), though |obj| could also mean abs(obj), but
presumably objects would only ever have __len__ or __abs__ and not both.
-.5 for a set literal syntax at all, -1 for offering your particular set
literal variant, -2 for your change propagating to dictionaries and
More information about the Python-3000