On Tue, Jul 30, 2013 at 11:19 AM, Musical Notation <musicdenotation@gmail.com> wrote:
Yes, I know that multiline lambda will never be implemented in Python, but in many languages it is possible to write an anonymous function without using lambda at all. In JavaScript: Instead of "function <name>(<variables>){code}" you can write "var name; name=function(<variables>){code}"
This seems like an odd misunderstanding to me. Of course Javascript has a lambda, it just happens to spell it 'f-u-n-c-t-i-o-n' rather than like 'l-a-m-b-d-a'. As with every other object, a lambda object can be assigned a name in Javascript... although it need not be, of course. You can also just use a Javascript lambda inline anywhere a code object makes sense, e.g.: higher_order_func(function(x,y){return x+y}, 2, 3); Of course, if you wanted to, you could have written: add2 = function(x,y){return x+y}; higher_order_func(add2, 2, 3); Or likewise: function add2(x,y){return x+y}; higher_order_func(add2, 2, 3); Other than not allowing full blocks in lambdas, Python is exactly the same. higher_order_func(lambda x,y: x+y, 2, 3) And as with Javascript, you *could* give the passed function a name with: add2 = lambda x,y: x+y Or with: def add2(x,y): return x+y It sounds like what you are asking for--after saying Python will never have it--is multi-line, full-block, lambdas in Python. For that, it has been discussed a lot of times, and no one has found a syntax that feel widely acceptable. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.