# On the first~classness of functions

**URL:** <https://discuss.python.org/t/on-the-first-classness-of-functions/12984>\
**Category:** Ideas\
**Created:** [January 9, 2022, 11:38am UTC](https://discuss.python.org/t/on-the-first-classness-of-functions/12984 "2022-01-09T11:38:55Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![CAM-Gerlach](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cam-gerlach/32/3688_2.png) [@CAM-Gerlach](https://discuss.python.org/u/CAM-Gerlach)\
**Post date:** [January 10, 2022, 12:18am UTC](https://discuss.python.org/t/on-the-first-classness-of-functions/12984/5 "2022-01-10T00:18:40Z")

</div>

> [@JohnHind](#):
>
> `myfunc = lambda x: x**2`

To note, many of the examples given assign the result of the lambda expression to a name, which is not an intended use of a `lambda` and highly discouraged/unidiomatic to begin with (as opposed to using `def`, as intended). See [this recent discussion](https://discuss.python.org/t/what-is-the-purpose-of-lambda-expressions/12415/17) for more on why, as well as how lambdas and their syntax fit into the language.

> [@JohnHind](#):
>
> If functions are objects, then function definitions should be object constructors.

As @steven.daprano points out, function object _are_ constructed via an object constructor, `types.FunctionType()`; its just rather tedious and inelegant to do so. At a low level, `def` and `lambda` can be roughly be thought of as syntactic sugar for `types.FunctionType()` that makes this far less painful, clearer and more elegant. Your proposed syntax is not an object constructor either, and fundamentally at odds with the basic grammar of Python with regard to statements, callables and blocks.

> [@JohnHind](#):
>
> Despite your inserting a crowbar into the tiny chink I left for the sake of terseness in my example, I think you can see that it removes that limitation.

While a minimal reproducible example is useful for isolating a bug, I think what we’re asking for here are _useful_ real-world (not just theoretical) examples where the limitation has serious negative repercussions, and the proposed new syntax would have substantial tangible benefits for a significant fraction of users sufficient to justify such a relatively large change.

> [@JohnHind](#):
>
> Does what I suggested “run into difficulty with parsing, or ambiguity”? At the moment, I cannot see why.

As both @steven.daprano and myself have mentioned, there are fundamental reasons (linked above and briefly discussed here) why the syntax is incompatible with the basic grammar of Python. At the minimum, there needs to be compelling real-world use cases that would justify the change, and a syntax and parsing grammar that would overcome the issues raised in past attempts. At this point, it seems rather unlikely to gain widespread support, but welcome to propose such.

---

_[View the full topic](https://discuss.python.org/t/on-the-first-classness-of-functions/12984)._
