Re: Proposed new syntax

2017-08-11 Thread Rustom Mody
On Friday, August 11, 2017 at 8:33:32 PM UTC+5:30, Ian wrote: > The grand-daddy of them all, NPL (which actually called them "set > comprehensions" after mathematics): > > setofeven(X) <= <:x: x in X & even(x) :> Thanks for reminding of NPL; will add it to my history summary at http://blog.langua

Re: Proposed new syntax

2017-08-11 Thread Steve D'Aprano
On Sat, 12 Aug 2017 12:45 am, Michael Torrie wrote: > On 08/10/2017 11:29 PM, Steve D'Aprano wrote: >> On Fri, 11 Aug 2017 12:54 pm, Mikhail V wrote: >> >>> but at a first glance, "while" reads as "if" as in english. >> >> In English the two words don't mean the same thing. > But actually in som

Re: Proposed new syntax

2017-08-11 Thread Ben Bacarisse
Steve D'Aprano writes: > Every few years, the following syntax comes up for discussion, with some > people > saying it isn't obvious what it would do, and others disagreeing and saying > that it is obvious. So I thought I'd do an informal survey. > > What would you expect this syntax to return?

Re: Proposed new syntax

2017-08-11 Thread Ian Kelly
On Thu, Aug 10, 2017 at 11:45 PM, Steve D'Aprano wrote: > On Fri, 11 Aug 2017 08:49 am, Ben Finney wrote: > >> The comprehension encourages thinking in sets: an operation that takes a >> collection as input, and emits a different collection, through one >> conceptual operation. >> >> Adding ‘while

Re: Proposed new syntax

2017-08-11 Thread Michael Torrie
On 08/10/2017 11:29 PM, Steve D'Aprano wrote: > On Fri, 11 Aug 2017 12:54 pm, Mikhail V wrote: > >> but at a first glance, "while" reads as "if" as in english. > > In English the two words don't mean the same thing. But actually in some contexts they really do seem to mean the same thing: Make h

Re: Proposed new syntax

2017-08-11 Thread Ian Kelly
On Fri, Aug 11, 2017 at 6:53 AM, Serhiy Storchaka wrote: > 10.08.17 23:28, Ian Kelly пише: >> >> So, perhaps a better syntax could be: >> >> [x + 1 for x in (0, 1, 2, 999, 3, 4) if x < 5 else break] > > > (0, 1, 2, 999, 3, 4) if x < 5 else break > > looks too similar to the ternary operator.

Re: Planning a Python Course for Beginners

2017-08-11 Thread Ned Batchelder
On 8/11/17 6:37 AM, Python wrote: > Marko Rauhamaa wrote: >> Python : >> >>> Marko Rauhamaa wrote: >>> I didn't disagree with any of these statements about __hash__, but only >>> your statement about id and __eq__: >>> id() is actually an ideal return value of __hash__(). The only criter

Re: Proposed new syntax

2017-08-11 Thread Marko Rauhamaa
Serhiy Storchaka : > 10.08.17 17:28, Steve D'Aprano пише: >> What would you expect this syntax to return? >> >> [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5] > > I would expect it to be equivalent to the following code: > > result = [] > for x in (0, 1, 2, 999, 3, 4): > while x

Re: Proposed new syntax

2017-08-11 Thread Serhiy Storchaka
10.08.17 23:28, Ian Kelly пише: So, perhaps a better syntax could be: [x + 1 for x in (0, 1, 2, 999, 3, 4) if x < 5 else break] (0, 1, 2, 999, 3, 4) if x < 5 else break looks too similar to the ternary operator. -- https://mail.python.org/mailman/listinfo/python-list

Re: Proposed new syntax

2017-08-11 Thread Serhiy Storchaka
10.08.17 17:28, Steve D'Aprano пише: Every few years, the following syntax comes up for discussion, with some people saying it isn't obvious what it would do, and others disagreeing and saying that it is obvious. So I thought I'd do an informal survey. What would you expect this syntax to return

Re: Proposed new syntax

2017-08-11 Thread Alain Ketterlin
Ian Kelly writes: > On Thu, Aug 10, 2017 at 8:28 AM, Steve D'Aprano > wrote: >> What would you expect this syntax to return? >> >> [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5] > > I would expect the for to be an outer loop and the while to be an > inner, so this would loop infinitely. +1.

Re: Planning a Python Course for Beginners

2017-08-11 Thread Python
Marko Rauhamaa wrote: Python : Marko Rauhamaa wrote: I didn't disagree with any of these statements about __hash__, but only your statement about id and __eq__: id() is actually an ideal return value of __hash__(). The only criterion is that the returned number should be different if the __e

Re: Proposed new syntax

2017-08-11 Thread Paul Rubin
Steve D'Aprano writes: > What would you expect this syntax to return? > [x + 1 for x in (0, 1, 2, 999, 3, 4) while x < 5] [1,2,3] though the later example is more confusing. I don't think we need this since we have itertools.takewhile: from operator import gt from functools import partial