On Fri, May 29, 2020 at 1:12 PM Alex Hall <alex.mojaki@gmail.com> wrote:
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
But if I understand correctly, a delayed value is concretized once, then the value is cached and remains concrete. So if we still have early binding, then x will only have one random value, unlike Stephen's lambda which generates a new value each time it's called.
I don't think that's required by the example code I wrote. The two things that are concretized, 'x' and 'w-b', are assigned to a different name. I'm taking that as meaning "walk the call graph to produce a value" rather than "transform the underlying object". So in the code, x and y would stay permanently as a special delayed object. This is a lot like a lambda, I recognize. The difference is that the intermediate computations would look through the right-hand side and see if anything was of DeferredType. If so, the computation would become "generate the derived call graph" rather than "do numeric operations." So, for example, 'w' also is DeferredType (and always will be, although it will fall out of scope when the function ends). In some cases, generating a call graph can be arbitrarily cheaper than the actual computation; passing around the call graph rather than the result can hence be worthwhile. -- 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.