On 29/05/2020 18:02, David Mertz wrote:
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.
Presumably "delayed" is something that would be automatically applied to
the actual parameter given, otherwise your call graphs might or might
not actually be call graphs depending on how the function was called.
What happens if I call "foo(y=0)" for instance?
There's some risk that this will introduce a brand new gotcha, "You
forgot to concretize your delayed parameter". I'm not agin it per se,
but I'd need to understand the value of it better I think. Also, I'm
pretty sure the average programmer will find the current
if x is None:
x = randint(0,9)
a lot easier to understand.
--
Rhodri James *-* Kynesim Ltd
_______________________________________________
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/WEAF5BHXHSO55V55ES2C4KWF6UO3T3FJ/
Code of Conduct: http://python.org/psf/codeofconduct/