Why not real anonymous functions?

Definitely true, although this does not prevent other languages from supporting anonymous function literals.

Also true, but one of the justifications for avoiding anoynmous function literals is that nested functions are a suitable replacement. So that’s not necessarily a good argument against anonymous function literals.

This is an opinion. A perfectly valid one, but I disagree. Also I think it’s interesting that all discussions about anonymous functions or function literals are framed in terms of lambdas. Lambdas are not the only solution to this problem. It’s just the one that Python happens to have chosen for a severely restricted implementation of anonymous functions.

This is fair and aligns with “explicit is better than implicit”. However, the economy I’m talking about isn’t really in terms of number of characters. It’s more in terms of syntactic parity. The fact that anonymous function literals are not supported as expressions in their own right seems inelegant to me.

A lot of people are asking “what has changed?” I think this is a strange line of questioning and merely serves as a rather tired defense of the status quo. What has changed is… everything, all the time. The world around us is constantly changing. We all encounter new problems and new ways of solving them. It’s reasonable to want to apply what we have learned and to approach old problems with new eyes.

My own opinion, informed by my experience with Rust and other languages, is that anonymous function literals are an elegant and useful construct. Personally I would love to use them in Python, especially as I gravitate more and more towards functional paradigms.

There may be perfectly good reasons that Python does not currently, and maybe will never, support anonymous function literals. But the question can and should be asked without any further justification.

1 Like