Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
Op 26-11-15 om 16:36 schreef Marko Rauhamaa: > Antoon Pardon : > >> [ for in ] >> >> would implicitly be rewritten as follows: >> >> [ (lambda : )() for in ] > > Funny enough, that's how "list comprehensions" are created in Scheme: > >(map (lambda (i) > (lambda (x) (* i

Re: What does a list comprehension do

2015-11-26 Thread Jussi Piitulainen
Antoon Pardon writes: > Op 26-11-15 om 14:56 schreef Marko Rauhamaa: >> Antoon Pardon wrote: >> >>> I don't understand. What I propose would be a minor change in how >>> list comprehension works. I don't see how your example can be turned >>> into a list comprehension. >> >> The list comprehension

Re: What does a list comprehension do

2015-11-26 Thread Marko Rauhamaa
Antoon Pardon : > [ for in ] > > would implicitly be rewritten as follows: > > [ (lambda : )() for in ] Funny enough, that's how "list comprehensions" are created in Scheme: (map (lambda (i) (lambda (x) (* i x))) '(0 1 2 3 > There would no change on how lamb

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
Op 26-11-15 om 14:56 schreef Marko Rauhamaa: > Antoon Pardon : > >> I don't understand. What I propose would be a minor change in >> how list comprehension works. I don't see how your example >> can be turned into a list comprehension. > The list comprehension is only a special case of the interact

Re: What does a list comprehension do

2015-11-26 Thread Marko Rauhamaa
Antoon Pardon : > I don't understand. What I propose would be a minor change in > how list comprehension works. I don't see how your example > can be turned into a list comprehension. The list comprehension is only a special case of the interaction between closures and variables. If you dabble wi

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
Op 26-11-15 om 13:56 schreef Marko Rauhamaa: > Antoon Pardon : > >> Personnaly I would prefer: >> > q = [(lambda i: lambda x: i * x)(i) for i in range(4)] > q[0](1), q[3](1) >> (0, 3) >> >> And this is where I ask whether it would be worth the effort to change >> the behaviour of python. >

Re: What does a list comprehension do

2015-11-26 Thread Marko Rauhamaa
Antoon Pardon : > Personnaly I would prefer: > q = [(lambda i: lambda x: i * x)(i) for i in range(4)] q[0](1), q[3](1) > (0, 3) > > And this is where I ask whether it would be worth the effort to change > the behaviour of python. Don't go there. Consider: q = [] n = 0 x =

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
Op 26-11-15 om 12:13 schreef Nobody: > Returning to the original expression: > > > q = [lambda x: i * x for i in range(4)] > > q[0](1), q[3](1) > (3, 3) > > q = [lambda x,i=i: i * x for i in range(4)] > > q[0](1), q[3](1) > (0, 3) Personnaly I would prefer: >>>

Re: What does a list comprehension do (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?))

2015-11-26 Thread Nobody
On Wed, 25 Nov 2015 14:51:23 +0100, Antoon Pardon wrote: > Am I missing something? The issue is with lambdas rather than with list comprehensions per se. Python's lambdas capture free variables by reference, not value. > x = 3 > f = lambda y: x + y > f(0) 3

Re: What does a list comprehension do

2015-11-25 Thread dieter
Antoon Pardon writes: > Op 20-11-15 om 08:49 schreef dieter: >> In addition, the last few days have had two discussions in this list >> demonstrating the conceptial difficulties of late binding -- one of them: >> >> Why does "[lambda x: i * x for i in range(4)]" gives >> a list of ess

What does a list comprehension do (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?))

2015-11-25 Thread Antoon Pardon
Op 20-11-15 om 08:49 schreef dieter: > In addition, the last few days have had two discussions in this list > demonstrating the conceptial difficulties of late binding -- one of them: > > Why does "[lambda x: i * x for i in range(4)]" gives > a list of essentially the same functions? C