On 26.10.2021 18:36, Erik Demaine wrote:
> On Tue, 26 Oct 2021, Marc-Andre Lemburg wrote:
> 
>> Now, it may not be obvious, but the key advantage of such
>> deferred objects is that you can pass them around, i.e. the
>> "defer os.listdir(DEFAULT_DIR)" could also be passed in via
>> another function.
> 
> Are deferred code pieces are dynamically scoped, i.e., they are evaluated in
> whatever scope they end up getting evaluated?  That would certainly 
> interesting,
> but also kind of dangerous (about as dangerous as eval), and I imagine fairly
> prone to error if they get passed around a lot. 

Yes, they would work more or less like copy & pasting the deferred
code into a new context and running it there.

Sure, you can abuse this, but the function running the deferred
can make sure that it's working in a trusted environment.

> If they're *not* dynamically
> scoped, then I think they're equivalent to lambda, and then they don't solve 
> the
> default parameter problem, because they'll be evaluated in the function's
> enclosing scope instead of the function's scope.

Indeed. Lambdas are similar, but not the same. The important part is
running the code in a different context.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Experts (#1, Oct 26 2021)
>>> Python Projects, Coaching and Support ...    https://www.egenix.com/
>>> Python Product Development ...        https://consulting.egenix.com/
________________________________________________________________________

::: We implement business ideas - efficiently in both time and costs :::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               https://www.egenix.com/company/contact/
                     https://www.malemburg.com/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NUA442RSNDSHKEYNUINRY727XT7OVS63/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to