<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Python&#8217;s lambda is broken!</title>
	<atom:link href="http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/feed/" rel="self" type="application/rss+xml" />
	<link>http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/</link>
	<description>Mathematics for computers</description>
	<lastBuildDate>Sun, 25 Jul 2010 09:06:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Andrej Bauer</title>
		<link>http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/comment-page-1/#comment-13475</link>
		<dc:creator>Andrej Bauer</dc:creator>
		<pubDate>Sun, 23 May 2010 05:18:12 +0000</pubDate>
		<guid isPermaLink="false">http://math.andrej.com/?p=184#comment-13475</guid>
		<description>@Evan: your argument can be applied to other constructs as well. In Python we do not really need dictionaries because they can be replaced by association lists. I can tell you from personal experience that dictionaries are far more confusing for students than lists. This line of reasoning does not work very well. But yes, a language needs a balanced set of features.

The question is whether lambda belongs to such a set. There are many reasons why the answer is positive. For example, lambda abstraction is one part of a fundamental mathematical concept, namely that of a &lt;b&gt;function&lt;/b&gt;, the other part being application (of a function to an argument). It seems clear to me that such a primitive concept can be useful and probably should be part of a language.

If we designed languages according to what &quot;production environment workers&quot; can comprehend, we&#039;d still be hunting with sticks and stones.</description>
		<content:encoded><![CDATA[<p>@Evan: your argument can be applied to other constructs as well. In Python we do not really need dictionaries because they can be replaced by association lists. I can tell you from personal experience that dictionaries are far more confusing for students than lists. This line of reasoning does not work very well. But yes, a language needs a balanced set of features.</p>
<p>The question is whether lambda belongs to such a set. There are many reasons why the answer is positive. For example, lambda abstraction is one part of a fundamental mathematical concept, namely that of a <b>function</b>, the other part being application (of a function to an argument). It seems clear to me that such a primitive concept can be useful and probably should be part of a language.</p>
<p>If we designed languages according to what &#8220;production environment workers&#8221; can comprehend, we&#8217;d still be hunting with sticks and stones.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Evan</title>
		<link>http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/comment-page-1/#comment-13474</link>
		<dc:creator>Evan</dc:creator>
		<pubDate>Sun, 23 May 2010 00:59:13 +0000</pubDate>
		<guid isPermaLink="false">http://math.andrej.com/?p=184#comment-13474</guid>
		<description>If a lambda function can be converted to work as a non-lambda function with little effort, why add the unnecessary complexity.

It&#039;s pretty obvious, that from a practical standpoint, most people can&#039;t inherently grasp the idiosyncrasies of lambda expressions. Otherwise, you wouldn&#039;t have so many comments on this thread explaining what it tries to accomplish.

I think, GvR has a pretty good understanding that his language is used extensively in production environments (not just academic); and, adding features for features sake is a mistake.

If you want a dynamically-typed, light-weight, functional programming language that supports useless constructs like lambda expressions why don&#039;t you write your own. Wait, there are already 11 different dialects of Lisp.

Don&#039;t forget, some of us actually use python to produce code to make money.</description>
		<content:encoded><![CDATA[<p>If a lambda function can be converted to work as a non-lambda function with little effort, why add the unnecessary complexity.</p>
<p>It&#8217;s pretty obvious, that from a practical standpoint, most people can&#8217;t inherently grasp the idiosyncrasies of lambda expressions. Otherwise, you wouldn&#8217;t have so many comments on this thread explaining what it tries to accomplish.</p>
<p>I think, GvR has a pretty good understanding that his language is used extensively in production environments (not just academic); and, adding features for features sake is a mistake.</p>
<p>If you want a dynamically-typed, light-weight, functional programming language that supports useless constructs like lambda expressions why don&#8217;t you write your own. Wait, there are already 11 different dialects of Lisp.</p>
<p>Don&#8217;t forget, some of us actually use python to produce code to make money.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Edvard Karlsen</title>
		<link>http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/comment-page-1/#comment-13439</link>
		<dc:creator>Edvard Karlsen</dc:creator>
		<pubDate>Tue, 11 May 2010 17:35:58 +0000</pubDate>
		<guid isPermaLink="false">http://math.andrej.com/?p=184#comment-13439</guid>
		<description>I don&#039;t see the big problem here. Obviously, it&#039;s a bit confusing, but as others have stated, this is often the way closures are implemented in modern multi-paradigm languages. In my opinion, this behaviour should be expected in this language with so much mutable state. Anyway, the problem here is not that the lambdas capture values, but how the for loop works.

However, to repeat earlier posters, there are other solutions.

&lt;code&gt;
&gt;&gt;&gt; a = lambda n: lambda nn: n + nn
&gt;&gt;&gt; a(3)(5)
8
&lt;/code&gt;

Starting with this approach is imho more flexible, clearer, reads better and possibly more memory efficient. If one then should need/want a list of a specific lambdas of this form, one could do so with classic list comprehension as suggested earlier. Stuff like &quot;i=i&quot; etc. are hacks that can easily be avoided :)</description>
		<content:encoded><![CDATA[<p>I don&#8217;t see the big problem here. Obviously, it&#8217;s a bit confusing, but as others have stated, this is often the way closures are implemented in modern multi-paradigm languages. In my opinion, this behaviour should be expected in this language with so much mutable state. Anyway, the problem here is not that the lambdas capture values, but how the for loop works.</p>
<p>However, to repeat earlier posters, there are other solutions.</p>
<p><code><br />
&gt;&gt;&gt; a = lambda n: lambda nn: n + nn<br />
&gt;&gt;&gt; a(3)(5)<br />
8<br />
</code></p>
<p>Starting with this approach is imho more flexible, clearer, reads better and possibly more memory efficient. If one then should need/want a list of a specific lambdas of this form, one could do so with classic list comprehension as suggested earlier. Stuff like &#8220;i=i&#8221; etc. are hacks that can easily be avoided :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: VaporWarning&#187; Blog Archive &#187; Notes from the JS pit: closure optimization</title>
		<link>http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/comment-page-1/#comment-13438</link>
		<dc:creator>VaporWarning&#187; Blog Archive &#187; Notes from the JS pit: closure optimization</dc:creator>
		<pubDate>Tue, 11 May 2010 10:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://math.andrej.com/?p=184#comment-13438</guid>
		<description>[...] closure-by-reference can produce side effects that surprise developers, such as: def surprise&#40;&#41;: funs = &#91;lambda: x ** 2 for x in range&#40;6&#41;&#93; assert [...]</description>
		<content:encoded><![CDATA[<p>[...] closure-by-reference can produce side effects that surprise developers, such as: def surprise&#40;&#41;: funs = &#91;lambda: x ** 2 for x in range&#40;6&#41;&#93; assert [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: joseanpg</title>
		<link>http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/comment-page-1/#comment-11985</link>
		<dc:creator>joseanpg</dc:creator>
		<pubDate>Tue, 09 Jun 2009 19:25:49 +0000</pubDate>
		<guid isPermaLink="false">http://math.andrej.com/?p=184#comment-11985</guid>
		<description>En Scheme la semántica básica de las capturas es la misma que en Python y JavaScript

(define (ruma) 
   (let ((k 10)(fs &#039;()))
     (define (r) 
         (if (= k 1)
            fs
           ((lambda () 
              (set! k (- k 1 ))
              (set! fs (cons (lambda () write k) fs))
              (r)
            )) 
         )
      )
      (r)
   )
)


Todas las funciones de la lista devuelta por esta función nos dan el valor 1, el último valor que toma k. Esto implica que las clausuras de la lista capturan la referencia a k, no su valor.</description>
		<content:encoded><![CDATA[<p>En Scheme la semántica básica de las capturas es la misma que en Python y JavaScript</p>
<p>(define (ruma)<br />
   (let ((k 10)(fs &#8216;()))<br />
     (define (r)<br />
         (if (= k 1)<br />
            fs<br />
           ((lambda ()<br />
              (set! k (- k 1 ))<br />
              (set! fs (cons (lambda () write k) fs))<br />
              (r)<br />
            ))<br />
         )<br />
      )<br />
      (r)<br />
   )<br />
)</p>
<p>Todas las funciones de la lista devuelta por esta función nos dan el valor 1, el último valor que toma k. Esto implica que las clausuras de la lista capturan la referencia a k, no su valor.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
