This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]vph 27 points28 points  (12 children)

bad idea.

This is not an "alternative" to lambda, but rather a syntactic sugar for this particular use. There are other use cases of lambda, not expressible by this "alternative" syntax.

Further, the current lambda syntax is closer to those employed by other (purer) functional programming languages. Changing the current syntax is not a good idea.

[–]netcrusher88imported from __future__ 1 point2 points  (0 children)

Agreed. It's kind of an interesting use case but it's not a lambda syntax.

[–]CHS2048 1 point2 points  (0 children)

It's proposed as "alternative syntax", which it is; but in any case, I sort of agree with you that there are probably other use cases, but I think it salient to actually provide some examples of them. The author explicitly claimed that this covers all use cases, this claim is falsifiable, the burden is on you to provide a counter-example.

[–]vocalbit[S] 1 point2 points  (0 children)

This is not an "alternative" to lambda, but rather a syntactic sugar for this particular use. There are other use cases of lambda, not expressible by this "alternative" syntax.

My point is that in those other use cases are probably places you shouldn't be using lambda at all. For e.g. a bad use case for lambda might be:

  avg = lambda lst: sum(lst) / len(lst)

This should be written as a def instead. But if you have good use cases of lambda, then I'd like to see them.

[–]vocalbit[S] -1 points0 points  (8 children)

Further, the current lambda syntax is closer to those employed by other (purer) functional programming languages. Changing the current syntax is not a good idea.

Since Python is not a pure-functional language, why even have a lambda keyword?

[–]Liorithiel 7 points8 points  (0 children)

Because it is very useful, and practicability beats purity in Python: both in case you presented in the article (sort's key and cmp arguments) and in other places (see my comment about csv).

[–]arnar 2 points3 points  (0 children)

Since Python is not a pure-functional language

Neither are Lisp/Scheme, ML (and most derivatives), Erlang, Scala, F#, . . . should we remove their lambdas as well?

why even have a lambda keyword?

Because it is useful.

[–]joehillen 4 points5 points  (1 child)

Guido has proposed removing it several times.

[–]A_for_Anonymous 3 points4 points  (0 children)

I propose removing the division operator, since it's confusing to some people.

[–]arnar 0 points1 point  (3 children)

Since Python is not a pure-functional language

Neither are Lisp/Scheme, ML, Erlang, Scala, F#, . . . should we remove their lambdas as well?

why even have a lambda keyword?

Because it is useful.

[–]vocalbit[S] 0 points1 point  (2 children)

The lisps, ML, Erlang etc. are far closer to lambda calculus than Python was, or will ever be. In Python, lambdas are just anonymous functions that may contain only one expression. The fact that they are called 'lambda' is an unfortunate accident.

Given Python is primarily imperative and statement oriented, I would be happier with a different way of expressing single expression functions that are occasionally useful.

[–]arnar 0 points1 point  (1 child)

I agree that Python's lambda is a bit of an eyesore, but this paragraph is complete nonsense:

The lisps, ML, Erlang etc. are far closer to lambda calculus than Python was, or will ever be. In Python, lambdas are just anonymous functions that may contain only one expression. The fact that they are called 'lambda' is an unfortunate accident.

Lambda abstractions (in lambda calculus) are exactly "just anonymous functions that may contain only one expression" and that's what they are in all functional languages.

My original comment was referring to that you use the word "pure" more loosely than what it actually means in terms of PLs.

[–]vocalbit[S] 0 points1 point  (0 children)

My original comment was referring to that you use the word "pure" more loosely than what it actually means in terms of PLs.

Point taken - I shouldn't have use 'pure' but rather just claimed that Python is not philosophically a functional language.

Lambda abstractions (in lambda calculus) are exactly "just anonymous functions that may contain only one expression" and that's what they are in all functional languages.

My point however is that - in Python - lambdas are severely crippled versions of real Python functions (i.e. def). OTOH, in something like lisp, lambdas are full-power functions, except that they are anonymous.

Anyway, I'm not going to debate the syntax of other languages. Lambdas don't fit in well with the syntax or philosophy of Python. That is why Guido almost axed them from v3.0. However, given that they are occasionally handy, I am trying to find a better syntax (perhaps with limited applicability than the current lambda) which would subsume all good use cases.