Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!zen.net.uk!hamilton.zen.co.uk!reader02.news.zen.co.uk.POSTED!not-for-mail From: Nobody Subject: Re: Something is rotten in Denmark... Date: Fri, 03 Jun 2011 14:07:43 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: <2_AFp.30000$241.24052@newsfe07.iad> <4de71c42$0$29983$c3e8da3$5496439d@news.astraweb.com> <87zkm0qyze.fsf@dpt-info.u-strasbg.fr> <94qlhsFkriU1@mid.individual.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 57 Organization: Zen Internet NNTP-Posting-Host: 967b4d4e.news.zen.co.uk X-Trace: DXC=S^gAiW6ken`ko]em;Y=Pd`YjZGX^207Pk`> 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 language's lambdas in this area. Changing it to > do early binding would be "going against generally accepted > semantics". In Lisp, it depends upon whether the free variable is bound: $ clisp [1]> (setq f (lambda (x) (+ x i))) # [2]> (setq i 7) 7 [3]> (apply f (list 4)) 11 [4]> (setq i 12) 12 [5]> (apply f (list 4)) 16 ^D $ clisp [1]> (let ((i 7)) (setq f (lambda (x) (+ x i)))) # [2]> (apply f (list 4)) 11 [3]> (setq i 12) 12 [4]> (apply f (list 4)) 11 ^D If the variable is bound, then the lambda creates a closure. And Python behaves the same way: > f = (lambda i: lambda x: x + i)(7) > f(4) 11 > i = 12 > f(4) 11 # If you really want a "let", this syntax is closer: # f = (lambda i = 7: lambda x: x + i)() The original semantics (from the lambda calculus) don't deal with the concept of mutable state. > If anything should be changed here, it's the for-loop, not lambda. Right. The for loop should bind the variable rather than set it.