# Why not real anonymous functions?

**URL:** <https://discuss.python.org/t/why-not-real-anonymous-functions/44513>\
**Category:** Ideas\
**Created:** [January 30, 2024, 2:27am UTC](https://discuss.python.org/t/why-not-real-anonymous-functions/44513 "2024-01-30T02:27:09Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![drdavella](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/drdavella/32/11792_2.png) [@drdavella](https://discuss.python.org/u/drdavella)\
**Post date:** [January 30, 2024, 5:01pm UTC](https://discuss.python.org/t/why-not-real-anonymous-functions/44513/11 "2024-01-30T17:01:13Z")

</div>

> [@tjreedy](#):
>
> Named functions have a name that is unique within its context and which can be printed in tracebacks.

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

> [@tjreedy](#):
>
> Non-nested functions can be tested.

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.

> [@tjreedy](#):
>
> Lambda expressions work best when obvious enough to not need testing and when unlikely to be a direct cause of an exception. In practice, they seem expressive enough to cover most of the cases where they are most appropriate.

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.

> [@tjreedy](#):
>
> This means naming intermediate objects when appropriate, even though this is not ‘economical’ with letters.

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.

---

_[View the full topic](https://discuss.python.org/t/why-not-real-anonymous-functions/44513)._
