
On Sat, 30 Oct 2021, Brendan Barnwell wrote:
I agree it seems totally absurd to add a type of deferred expression but restrict it to only work inside function definitions.
Functions are already a form of deferred evaluation. PEP 671 is an embellishment to this mechanism for some of the code in the function signature to actually get executed within the body scope, *just like the body of the function*. This doesn't seem weird to me.
If we have a way to create deferred expressions we should try to make them more generally usable.
Does anyone have a proposal for deferred expressions that could match the ease of use of PEP 671 in assigning a default argument of, say, `[]`? The proposals I've seen so far in this thread involve checking `isdeferred` and then resolving that deferred. This doesn't seem any easier than the existing sentinal approach for default arguments, whereas PEP 671 significantly simplifies this use-case. I also don't see how a function could distinguish a deferred default argument and a deferred argument passed in from another function. In my opinion, the latter would be really messy/dangerous to work with, because it could arbitrarily polute your scope. Whereas late-bound default arguments make a lot of sense: they're written in the function itself (just in the signature instead of the body), so we can see by looking at the code what happens. I've written code in dynamically scoped languages before. I don't recall enjoying it. But maybe I missed a proposal, or someone has an idea for how to fix these issues. Erik -- Erik Demaine | edemaine@mit.edu | http://erikdemaine.org/