Re: Something is rotten in Denmark...

2011-06-05 Thread rusi
On Jun 3, 11:17 am, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: rusi writes: So I tried: Recast the comprehension as a map Rewrite the map into a fmap (functionalmap) to create new bindings def fmap(f,lst):     if not lst: return []     return [f(lst[0])] + fmap(f, lst[1:])

Re: Something is rotten in Denmark...

2011-06-05 Thread Jussi Piitulainen
rusi writes: On Jun 3, 11:17 am, Jussi Piitulainen wrote: rusi writes: So I tried: Recast the comprehension as a map Rewrite the map into a fmap (functionalmap) to create new bindings def fmap(f,lst):     if not lst: return []     return [f(lst[0])] + fmap(f, lst[1:])

Re: Something is rotten in Denmark...

2011-06-05 Thread rusi
On Jun 5, 5:03 pm, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: rusi writes: On Jun 3, 11:17 am, Jussi Piitulainen wrote: rusi writes: So I tried: Recast the comprehension as a map Rewrite the map into a fmap (functionalmap) to create new bindings def fmap(f,lst):  

Re: Something is rotten in Denmark...

2011-06-05 Thread Jussi Piitulainen
rusi writes: On Jun 5, 5:03 pm, Jussi Piitulainen wrote: rusi writes: On Jun 3, 11:17 am, Jussi Piitulainen wrote: rusi writes: So I tried: Recast the comprehension as a map Rewrite the map into a fmap (functionalmap) to create new bindings def fmap(f,lst):    

Re: Something is rotten in Denmark...

2011-06-03 Thread Jussi Piitulainen
rusi writes: So I tried: Recast the comprehension as a map Rewrite the map into a fmap (functionalmap) to create new bindings def fmap(f,lst): if not lst: return [] return [f(lst[0])] + fmap(f, lst[1:]) Still the same effects. Obviously I am changing it at the wrong place...

Re: Something is rotten in Denmark...

2011-06-03 Thread Thomas Rachel
Am 03.06.2011 01:43 schrieb Gregory Ewing: It's not the lambda that's different from other languages, it's the for-loop. In languages that encourage a functional style of programming, the moral equivalent of a for-loop is usually some construct that results in a new binding of the control

Re: Something is rotten in Denmark...

2011-06-03 Thread Alain Ketterlin
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Alain Ketterlin wrote: But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest computing abstraction, and they are at the core of any functional programming language. Yes, and Python's

Re: Something is rotten in Denmark...

2011-06-03 Thread Jussi Piitulainen
Alain Ketterlin writes: Gregory Ewing writes: Alain Ketterlin wrote: But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest computing abstraction, and they are at the core of any functional programming language. Yes, and

Re: Something is rotten in Denmark...

2011-06-03 Thread Nobody
On Fri, 03 Jun 2011 11:43:54 +1200, Gregory Ewing wrote: But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest computing abstraction, and they are at the core of any functional programming language. Yes, and Python's lambdas behave

Re: Something is rotten in Denmark...

2011-06-03 Thread Ian Kelly
On Fri, Jun 3, 2011 at 2:30 AM, Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de wrote: So there should be a way to replace the closure of a function with a snapshot of it at a certain time. If there was an internal function with access to the readonly attribute

Re: Something is rotten in Denmark...

2011-06-03 Thread harrismh777
Alain Ketterlin wrote: The reason why we have the kind of lambdas we have in python (and scheme, and javascript, etc.) is just that it is way easier to implement. That's all I've said. And people have gotten used to it, without ever realizing they are using something completely different from

Re: Something is rotten in Denmark...

2011-06-03 Thread Gregory Ewing
Alain Ketterlin wrote: You must be kidding. Like many others, you seem to think that Scheme is a typical functional language, which it is not. I never said that Scheme is a functional language -- I'd be the first to acknowledge that it's not. I do know what real functional languages are like.

Re: Something is rotten in Denmark...

2011-06-02 Thread Terry Reedy
On 6/1/2011 8:40 PM, harrismh777 wrote: The part that I don't see much about in the docs (some books, that is) is that the lambda lookups occur late (the lambda is evaluated at the time it is called). The Python docs on-line *do say* this (I found too late) but its one quick phrase that can be

Re: Something is rotten in Denmark...

2011-06-02 Thread Chris Angelico
On Thu, Jun 2, 2011 at 3:14 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: The problem with Do What I Mean is that it so rarely Does What You Mean. At best it Does What Some Other Guy Imagined I'd Probably Mean In This Situation. Let's not go there. +1 One of my biggest

Re: Something is rotten in Denmark...

2011-06-02 Thread Alain Ketterlin
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: The part that I don't see much about in the docs (some books, that is) is that the lambda lookups occur late (the lambda is evaluated at the time it is called). The Python docs on-line *do say* this (I found too late) but its one

Re: Something is rotten in Denmark...

2011-06-02 Thread Jussi Piitulainen
Alain Ketterlin writes: Steven D'Aprano writes: I agree it's not intuitive. But where does it say that programming language semantics must always be intuitive? Nowhere. But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest

Re: Something is rotten in Denmark...

2011-06-02 Thread harrismh777
Steven D'Aprano wrote: funcs = [(lambda x, i=j: x+i) for j in range(10)] Now the reader is no longer distracted by the i=i ugliness. That's a good idea, in fact, change made! The problem with Do What I Mean is that it so rarely Does What You Mean. At best it Does What Some Other Guy

Re: Something is rotten in Denmark...

2011-06-02 Thread harrismh777
Steven D'Aprano wrote: What do you expect this code to do? a = 42 funcs = [(lambda x: x+a) for i in range(10)] funcs[0](1) I do see your point with this... truly... but it did get me to think about what I *do* expect... and that is that 'a' (for the lambda) will be whatever 'a' is (now)

Re: Something is rotten in Denmark...

2011-06-02 Thread harrismh777
Terry Reedy wrote: Oh the irony of this proposal. You scolded us for breaking code with 2 to 3 changes, and here you propose a change more radical than anything done in Python 3, and certain to break code, introduce bugs, complicate the language, and reduce its functionality. Most of Guido's

Re: Something is rotten in Denmark...

2011-06-02 Thread Steven D'Aprano
On Thu, 02 Jun 2011 10:55:49 -0500, harrismh777 wrote: Steven D'Aprano wrote: What do you expect this code to do? a = 42 funcs = [(lambda x: x+a) for i in range(10)] funcs[0](1) I do see your point with this... truly... but it did get me to think about what I *do* expect... and that

Re: Something is rotten in Denmark...

2011-06-02 Thread Ian Kelly
On Thu, Jun 2, 2011 at 11:22 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: It seems to me that early binding is less flexible than late, because with late binding you have a chance to simulate early binding by saving a reference of the variable elsewhere, such as in a default

Re: Something is rotten in Denmark...

2011-06-02 Thread Terry Reedy
On 6/2/2011 7:00 AM, Alain Ketterlin wrote: Nowhere. But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest computing abstraction, and they are at the core of any functional programming language. Adding a quick hack to python and call it

Re: Something is rotten in Denmark...

2011-06-02 Thread Gregory Ewing
Alain Ketterlin wrote: But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest computing abstraction, and they are at the core of any functional programming language. Yes, and Python's lambdas behave exactly the *same* way as every other

Re: Something is rotten in Denmark...

2011-06-02 Thread rusi
On Jun 3, 4:43 am, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Alain Ketterlin wrote: But going against generally accepted semantics should at least be clearly indicated. Lambda is one of the oldest computing abstraction, and they are at the core of any functional programming language.

Re: Something is rotten in Denmark...

2011-06-01 Thread Terry Reedy
On 5/31/2011 8:09 PM, harrismh777 wrote: At the moment I'm only speaking about my OP and that particular list comprehension... the thing that happened (at least for me) is that the intuitive sense that each 'i' somehow becomes a part of the anonymous function (I know, not so) is built-in. There

Re: Something is rotten in Denmark...

2011-06-01 Thread harrismh777
Terry Reedy wrote: function (I know, not so) is built-in. There is little to nothing indicating in the docs that this is not so On the contrary, the docs very explicitly say that a lambda expression is equivalent to a def statement. Allow me to clarify... I'm not speaking about whether the

Re: Something is rotten in Denmark...

2011-06-01 Thread harrismh777
harrismh777 wrote: Allow me to clarify... I'm not speaking about whether the lambda is short-hand for def, ... that part of the docs I understand well!... no problems there. Allow me to clarify a little further... the docs are misleading in that they state that the lambda can be coded (as

Re: Something is rotten in Denmark...

2011-06-01 Thread Steven D'Aprano
On Wed, 01 Jun 2011 19:50:14 -0500, harrismh777 wrote: harrismh777 wrote: Allow me to clarify... I'm not speaking about whether the lambda is short-hand for def, ... that part of the docs I understand well!... no problems there. Allow me to clarify a little further... the docs are

Re: Something is rotten in Denmark...

2011-06-01 Thread Steven D'Aprano
On Wed, 01 Jun 2011 19:40:30 -0500, harrismh777 wrote: The part that I don't see much about in the docs (some books, that is) is that the lambda lookups occur late (the lambda is evaluated at the time it is called). The Python docs on-line *do say* this (I found too late) but its one quick

Something is rotten in Denmark...

2011-05-31 Thread harrismh777
fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good ( that was a big surprise! . . . ) ( let's try it another way . . . ) fs =[] def g(i): return (lambda n: i + n) fs = [g(i) for i in range(10)]

Re: Something is rotten in Denmark...

2011-05-31 Thread Chris Rebert
On Mon, May 30, 2011 at 11:48 PM, harrismh777 harrismh...@charter.net wrote: fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]         === not good    ( that was a big surprise! . . . ) snip     lambda?  closure?  

Re: Something is rotten in Denmark...

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 12:48 AM, harrismh777 harrismh...@charter.net wrote:     What is going on with the binding in the first construct... this seems to reduce the usefulness of lambda to a considerable extent? I don't see why; as you've shown there are a couple of simple ways to avoid this

Re: Something is rotten in Denmark...

2011-05-31 Thread Jussi Piitulainen
harrismh777 writes: fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good ( that was a big surprise! . . . ) ( let's try it another way . . . ) The ten functions share the same i. The

Re: Something is rotten in Denmark...

2011-05-31 Thread Thomas Rachel
Am 31.05.2011 12:08 schrieb Jussi Piitulainen: The same sharing-an-i thing happens here: fs = [] for i in range(4): ...fs.append(lambda n : i + n) ... fs[0](0) 3 And the different private-j thing happens here: gs = [] for i in range(4): ...gs.append((lambda j : lambda n : j +

Re: Something is rotten in Denmark...

2011-05-31 Thread Jussi Piitulainen
Thomas Rachel writes: Am 31.05.2011 12:08 schrieb Jussi Piitulainen: The same sharing-an-i thing happens here: fs = [] for i in range(4): ...fs.append(lambda n : i + n) ... fs[0](0) 3 And the different private-j thing happens here: gs = [] for i in range(4): ...

Re: Something is rotten in Denmark...

2011-05-31 Thread Terry Reedy
On 5/31/2011 2:48 AM, harrismh777 wrote: fs=[] Irrelevant here since you immediately rebind 'fs'. fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)] Same as [f(1) for f in fs] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good ( that was a big surprise! . . . )

Re: Something is rotten in Denmark...

2011-05-31 Thread harrismh777
Terry Reedy wrote: You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant expression*, so you get 10 'equal' functions. 'hypnotized' indeed! ... ok, so let me see if I get this... the lambda defers lookup|bind of its references until such time as the lambda is 'called' and not

Re: Something is rotten in Denmark...

2011-05-31 Thread Martin Manns
On Tue, 31 May 2011 01:48:05 -0500 harrismh777 harrismh...@charter.net wrote: fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] === not good ( that was a big surprise! . . . ) ( let's try it

Re: Something is rotten in Denmark...

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 3:14 PM, Martin Manns mma...@gmx.net wrote: $ python Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. fs=[] fs = [(lambda n: i + n) for i in range(10)] [fs[i](1) for i in range(10)]

Re: Something is rotten in Denmark...

2011-05-31 Thread harrismh777
Martin Manns wrote: After being confused I figured out it is a 3.x example: Actually, it is a compatibility example between 2.x and 3.x, compare below for different behavior from two seemingly identical compatible constructs, one from 3.2, and the other from 2.6.4: Python 3.2 (r32:88445,

Re: Something is rotten in Denmark...

2011-05-31 Thread harrismh777
harrismh777 wrote: PS Ian calls the second construct working by mistake... oops, actually he called it, working by accident... -- http://mail.python.org/mailman/listinfo/python-list

Re: Something is rotten in Denmark...

2011-05-31 Thread Ian Kelly
On Tue, May 31, 2011 at 2:18 PM, harrismh777 harrismh...@charter.net wrote: If I'm understanding that correctly, then that means lambda is working as designed, and that there are very subtle nuances to be aware of. In my little case   (lambda n: i + n)   ... if the  i  goes out of scope

Re: Something is rotten in Denmark...

2011-05-31 Thread Chris Angelico
On Wed, Jun 1, 2011 at 7:53 AM, harrismh777 harrismh...@charter.net wrote:     Having compared the two, someone please tell me whether the two are incompatible, mostly compatible, completely incompatible, or different languages... By implication, every version of Python is incompatible with

Re: Something is rotten in Denmark...

2011-05-31 Thread Chris Angelico
On Wed, Jun 1, 2011 at 8:39 AM, Chris Angelico ros...@gmail.com wrote: - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links  across devices. PS. I know nothing about this particular issue, I just skimmed down the release notes and stopped when something caught my eye.

Re: Something is rotten in Denmark...

2011-05-31 Thread Terry Reedy
On 5/31/2011 4:18 PM, harrismh777 wrote: Terry Reedy wrote: You have been hypnotizeed by lambda. (lambda n: i+n) is a *constant expression*, so you get 10 'equal' functions. 'hypnotized' indeed! I say 'hypnotized' ;-) because people have posted examples almost exactly like the one you

Re: Something is rotten in Denmark...

2011-05-31 Thread harrismh777
Terry Reedy wrote: This is early-binding versus late-binding. Python is a late-binding language. ok ... Are you asking about changing all function compilation or only when functions are defined with lambda expressions? At least lambda expressions, but (see below) any other built-in

Re: Something is rotten in Denmark...

2011-05-31 Thread Martin Manns
On Tue, 31 May 2011 15:47:33 -0600 Ian Kelly ian.g.ke...@gmail.com wrote: The i variable is part of the global scope, and as you iterate over range(10) again it coincidentally takes on the same values as in the original list comprehension. You don't see this in Python 3 because the scope of