Re: [Python-3000] Set literals

2006-08-29 Thread Georg Brandl
Guido van Rossum wrote: > On 8/28/06, Georg Brandl <[EMAIL PROTECTED]> wrote: >> At python.org/sf/1547796, there is a preliminary patch for Py3k set literals >> as specified in PEP 3100. > > Very cool! This is now checked in. > > Georg, can you do something about repr() of an empty set? This > cu

Re: [Python-3000] Set literals

2006-08-28 Thread Georg Brandl
Raymond Hettinger wrote: > Georg Brandl wrote: > >>In the meantime, I played around with the peepholer and tried to copy >>the "for x in tuple_or_list" optimization for sets. Results are in SF >>patch #1548082. >> > Did you mean "if x in tuple_or_list"? IIRC, there was some reason that > mutabl

Re: [Python-3000] Set literals

2006-08-28 Thread Georg Brandl
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 >> n

Re: [Python-3000] Set literals

2006-08-28 Thread Guido van Rossum
On 8/28/06, Georg Brandl <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > >> > Georg, can you do something about repr() of an empty set? This > >> > currently produces "{}" while it should produce "set()". > >> > >> Right, forgot about that case. I'll correct that now. > >> (Grr, I even min

Re: [Python-3000] Set literals

2006-08-28 Thread Raymond Hettinger
Georg Brandl wrote: >In the meantime, I played around with the peepholer and tried to copy >the "for x in tuple_or_list" optimization for sets. Results are in SF >patch #1548082. > > > Did you mean "if x in tuple_or_list"? IIRC, there was some reason that mutable lists were not supposed to be

Re: [Python-3000] Set literals

2006-08-28 Thread Georg Brandl
Guido van Rossum wrote: >> > Georg, can you do something about repr() of an empty set? This >> > currently produces "{}" while it should produce "set()". >> >> Right, forgot about that case. I'll correct that now. >> (Grr, I even mindlessly changed the unittest that would have caught it) > > Chec

Re: [Python-3000] Set literals

2006-08-28 Thread Guido van Rossum
On 8/28/06, Georg Brandl <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > On 8/28/06, Georg Brandl <[EMAIL PROTECTED]> wrote: > >> At python.org/sf/1547796, there is a preliminary patch for Py3k set > >> literals > >> as specified in PEP 3100. > > > > Very cool! This is now checked in. > >

Re: [Python-3000] Set literals

2006-08-28 Thread Georg Brandl
Guido van Rossum wrote: > On 8/28/06, Georg Brandl <[EMAIL PROTECTED]> wrote: >> At python.org/sf/1547796, there is a preliminary patch for Py3k set literals >> as specified in PEP 3100. > > Very cool! This is now checked in. Wow, that's fast... > Georg, can you do something about repr() of an e

Re: [Python-3000] Set literals

2006-08-28 Thread Guido van Rossum
On 8/28/06, Georg Brandl <[EMAIL PROTECTED]> wrote: > At python.org/sf/1547796, there is a preliminary patch for Py3k set literals > as specified in PEP 3100. Very cool! This is now checked in. Georg, can you do something about repr() of an empty set? This currently produces "{}" while it should

[Python-3000] Set literals

2006-08-28 Thread Georg Brandl
At python.org/sf/1547796, there is a preliminary patch for Py3k set literals as specified in PEP 3100. Set comprehensions are not implemented. have fun, Georg ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/p

Re: [Python-3000] Set literals - another try

2006-08-09 Thread Guido van Rossum
On 8/8/06, Collin Winter <[EMAIL PROTECTED]> wrote: > 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. Let me clear up this misunderstanding. Optimizations have nothin

Re: [Python-3000] Set literals - another try

2006-08-09 Thread Guido van Rossum
> On 8/9/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > > 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

Re: [Python-3000] Set literals - another try

2006-08-09 Thread Guido van Rossum
On 8/8/06, Talin <[EMAIL PROTECTED]> 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 expa

Re: [Python-3000] Set literals - another try

2006-08-09 Thread Jim Jewett
On 8/9/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > 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 d

Re: [Python-3000] Set literals - another try

2006-08-09 Thread Nick Coghlan
Collin Winter wrote: > On 8/8/06, Josiah Carlson <[EMAIL PROTECTED]> 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.

Re: [Python-3000] Set literals - another try

2006-08-08 Thread Josiah Carlson
"Collin Winter" <[EMAIL PROTECTED]> wrote: > > On 8/8/06, Josiah Carlson <[EMAIL PROTECTED]> 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 liter

Re: [Python-3000] Set literals - another try

2006-08-08 Thread Collin Winter
On 8/8/06, Josiah Carlson <[EMAIL PROTECTED]> 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

Re: [Python-3000] Set literals - another try

2006-08-08 Thread Josiah Carlson
Talin <[EMAIL PROTECTED]> 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

[Python-3000] Set literals - another try

2006-08-08 Thread Talin
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 |) a

Re: [Python-3000] set literals

2006-07-20 Thread Ron Adam
Raymond Hettinger wrote: > I'm curious as to whether people will find one-type-with-two-purposes > easier to learn that what we have now. My experience so far is that > sets have a near zero learning curve as they are currently implemented. And it's not just about ease of learning to use, b

Re: [Python-3000] set literals

2006-07-17 Thread Jack Diederich
On Mon, Jul 17, 2006 at 02:54:14PM -0700, Guido van Rossum wrote: > Hm. Your objections seem to be purely from a performance tuning POV. I > think that if we agree that API-wise this is an improvement (fewer > things to learn, set literals problem solved, and dicts grow some > useful new methods) w

Re: [Python-3000] set literals

2006-07-17 Thread CM
On 7/17/06, Guido van Rossum <[EMAIL PROTECTED]> wrote: Hm. Your objections seem to be purely from a performance tuning POV. Ithink that if we agree that API-wise this is an improvement (fewerthings to learn, set literals problem solved, and dicts grow someuseful new methods) we should make a decis

Re: [Python-3000] set literals

2006-07-17 Thread Guido van Rossum
Hm. Your objections seem to be purely from a performance tuning POV. I think that if we agree that API-wise this is an improvement (fewer things to learn, set literals problem solved, and dicts grow some useful new methods) we should make a decision to do it and damn the tuning (I trust Raymond wil

Re: [Python-3000] set literals

2006-07-17 Thread Michael Chermside
Guido writes: > I've also sometimes thought of unifying dicts and sets by implementing > set operations on the keys of dicts only. [... much discussion ...] > I'm still very much undecided but I don't want to rule this out for > py3k. Perhaps I'll write up a PEP and see how it flies. Playing w

Re: [Python-3000] set literals

2006-07-13 Thread Fredrik Lundh
> we haven't had that for long, and I cannot recall anyone being puzzled by the > fact that you can use a dictionary of (item, None) pairs to efficiently > represent > a set. message += " before set was added to the language" ___ Python-3000 maili

Re: [Python-3000] set literals

2006-07-13 Thread Fredrik Lundh
Greg Ewing wrote: >> I say nuke it. Who needs it? > > There are algorithms which effectively involve a > mapping keyed by a set. E.g. converting an NFA > to a DFA requires building up sets of states from > the NFA and associating each one with a state in > the DFA. > > You can kludge around it, bu

Re: [Python-3000] set literals

2006-07-13 Thread Fredrik Lundh
Raymond Hettinger wrote: > I'm curious as to whether people will find one-type-with-two-purposes > easier to learn that what we have now. we haven't had that for long, and I cannot recall anyone being puzzled by the fact that you can use a dictionary of (item, None) pairs to efficiently represen

Re: [Python-3000] set literals

2006-07-10 Thread Raymond Hettinger
There would be some implementation consequences in terms of speed and memory usage (we would lose the memory savings and some of the speed-ups gained in the Py2.5 implementation of sets). Is that really necessary? Couldn't the keys and values be kept in separate arrays, an

Re: [Python-3000] set literals

2006-07-10 Thread Diogo Kollross
> I'm curious as to whether people will find one-type-with-two-purposes > easier to learn that what we have now. I see no problem with that. We already have lists-that-can-work-as-stacks-or-queues. ___ Python-3000 mailing list Python-3000@python.org http

Re: [Python-3000] set literals

2006-07-10 Thread Greg Ewing
Guido van Rossum wrote: > On 7/10/06, Diogo Kollross <[EMAIL PROTECTED]> wrote: > >>While we're at it... what happens to frozenset? > > I say nuke it. Who needs it? There are algorithms which effectively involve a mapping keyed by a set. E.g. converting an NFA to a DFA requires building up sets

Re: [Python-3000] set literals

2006-07-10 Thread Guido van Rossum
On 7/10/06, Diogo Kollross <[EMAIL PROTECTED]> wrote: > While we're at it... what happens to frozenset? I say nuke it. Who needs it? -- --Guido van Rossum (home page: http://www.python.org/~guido/) ___ Python-3000 mailing list Python-3000@python.org ht

Re: [Python-3000] set literals

2006-07-10 Thread Greg Ewing
Raymond Hettinger wrote: > The outermost set coercion is not especially attractive or efficient. > Since equality/inequality is an important set operation, we would likely > need to add a method for equality testing that ignores dict values: Or coerction to a set could return a "set view" that

Re: [Python-3000] set literals

2006-07-10 Thread Greg Ewing
Diogo Kollross wrote: > While we're at it... what happens to frozenset? Probably it becomes an immutable subsclass of dict. Then, since the word 'set' is now free, we can rename the somewhat awkward-sounding 'frozenset' to 'set'. There would then be a nice symmetry between list/tuple and dict/s

Re: [Python-3000] set literals

2006-07-10 Thread Greg Ewing
Raymond Hettinger wrote: > There would be some implementation consequences in terms of speed and > memory usage (we would lose the memory savings and some of the speed-ups > gained in the Py2.5 implementation of sets). Is that really necessary? Couldn't the keys and values be kept in separate a

Re: [Python-3000] set literals

2006-07-10 Thread Raymond Hettinger
Guido van Rossum wrote: >> >> The deeper problem is that decisions on which values to keep will >> inevitability break set invariants (see a long list of these in >> test.test_set.py): >> >>assert a|b == b|a, 'commutative property' >>assert (a-b) | (a&b) | (b-a) == a|b, 'whole is the sum o

Re: [Python-3000] set literals

2006-07-10 Thread Diogo Kollross
While we're at it... what happens to frozenset? ___ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Re: [Python-3000] set literals

2006-07-10 Thread Guido van Rossum
On 7/10/06, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > >I've also sometimes thought of unifying dicts and sets by implementing > >set operations on the keys of dicts only. When the values aren't the > >same, we could make an arbitrary decision e.g. the left operand w

Re: [Python-3000] set literals

2006-07-10 Thread Raymond Hettinger
Guido van Rossum wrote: >I've also sometimes thought of unifying dicts and sets by implementing >set operations on the keys of dicts only. When the values aren't the >same, we could make an arbitrary decision e.g. the left operand wins. >You get quite far. E.g. > >a = {1: "a", 2: "b"} >b = {1: "c"

Re: [Python-3000] set literals

2006-07-10 Thread Terry Reedy
"Guido van Rossum" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> > Unfortunately we couldn't redefine <=, <, >=, > to mean various >> > subset/superset tests without backwards incompatibilities (but does >> > anyone care? >> >> You mean those are defined *now*? I'm trying to figu

Re: [Python-3000] set literals

2006-07-10 Thread Guido van Rossum
On 7/10/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > I've also sometimes thought of unifying dicts and sets by implementing > > set operations on the keys of dicts only. When the values aren't the > > same, we could make an arbitrary decision e.g. the left operand wins.

Re: [Python-3000] set literals

2006-07-10 Thread Alexander Belopolsky
Guido van Rossum: > # We could use these equivalencies: > assert {1} == {1: None} == set({1: "a"}) # I.e. canonical sets have > all None values An alternative canonical representation of a set as a dict could be a dict d for which d[k] is k for k in d.keys(). Guido van Rossum: > Also, sets wou

Re: [Python-3000] set literals

2006-07-10 Thread Nick Coghlan
Guido van Rossum wrote: > I've also sometimes thought of unifying dicts and sets by implementing > set operations on the keys of dicts only. When the values aren't the > same, we could make an arbitrary decision e.g. the left operand wins. If the right operand always won then a |= b would be equiv

Re: [Python-3000] set literals

2006-07-09 Thread Greg Ewing
Andrew Koenig wrote: > Or you could adopt the approach used by SETL: A dict is equivalent to a set > of 2-tuples. > > No, I'm not serious; I think it would be too big a change. But you have to > admit it's a cool idea :-) One fairly disastrous consequence would be that the *values* would have t

Re: [Python-3000] set literals

2006-07-09 Thread Guido van Rossum
I've also sometimes thought of unifying dicts and sets by implementing set operations on the keys of dicts only. When the values aren't the same, we could make an arbitrary decision e.g. the left operand wins. You get quite far. E.g. a = {1: "a", 2: "b"} b = {1: "c", 3: "d"} # These already work:

Re: [Python-3000] set literals

2006-07-08 Thread Diogo Kollross
> str and unicode are *distinct* types. they may be related, but not in > the sense that type("hello") and type(r"hello") both return str. They're distinct types, but not that distinct: Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credi

Re: [Python-3000] set literals

2006-07-08 Thread Andrew Koenig
> moreover, you can say a set is a "kind of" a keys-only dict. in fact, > the first implementation of set used a dict, where the keys where the > elements of the set, and their value was always True. Or you could adopt the approach used by SETL: A dict is equivalent to a set of 2-tuples. In other

Re: [Python-3000] set literals

2006-07-07 Thread Guido van Rossum
-1. On 7/7/06, tomer filiba <[EMAIL PROTECTED]> wrote: > i had this idea -- since quoted literals can be prefixed by a letter > that alters their meaning, why not use the same semantics > with curly braces? > > "hello" -- byte string literal > r"hello" -- unescaped byte string literal > u"hello" -

Re: [Python-3000] set literals

2006-07-07 Thread tomer filiba
str and unicode are *distinct* types. they may be related, but not in the sense that type("hello") and type(r"hello") both return str. moreover, you can say a set is a "kind of" a keys-only dict. in fact, the first implementation of set used a dict, where the keys where the elements of the set, an

Re: [Python-3000] set literals

2006-07-07 Thread Diogo Kollross
> i had this idea -- since quoted literals can be prefixed by a letter > that alters their meaning, why not use the same semantics > with curly braces? String literals are always strings, no matter what kind of string as defined by the prefix. On the other hand, dictionaries and sets seems differe

[Python-3000] set literals

2006-07-07 Thread tomer filiba
i had this idea -- since quoted literals can be prefixed by a letter that alters their meaning, why not use the same semantics with curly braces? "hello" -- byte string literal r"hello" -- unescaped byte string literal u"hello" -- unicode string literal {1:2, 3:4, 5:6} -- dict literal s{1, 2, 3}