On Fri, May 29, 2020 at 3:19 AM Stephen J. Turnbull <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:

>     # Just too ugly for me!
>     def foo(x=lambda: random.randint(0,9)):
>
>         x = x()
>         # ...
>

I think this is a perfect example of where my desired "delayed" (or
"deferred") construct would be great.  There are lots of behaviors that I
have not thought through, and do not specify here.  But for example:

def foo(a=17, b=42,, x=delayed randint(0,9), y=delayed randrange(1,100)):
    if something:
        # The simple case is realizing a direct delayed
        val = concretize x
    elif something_else:
        # This line creates a call graph, not a computation
        z = ((y + 3) * x)**10
        # Still call graph land
        w = a / z
        # Only now do computation (and decide randoms)
        val = concretize w - b

I do not find this particularly ugly, and I think the intent is pretty
clear.  I chose two relatively long words, but some sort of shorter
punctuation would be possible, but less intuitive to my mind.


-- 
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.
_______________________________________________
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/UOXBYGFPJL6EK3EVFYT3LJJHACYEAQ43/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to