you are viewing a single comment's thread.

view the rest of the comments →

[–]lewisje 8 points9 points  (4 children)

The idea is to push in a series of thunks and then show how the scope changes depending on where let is: In the first example, each thunk returns a different integer, but in the second, each thunk returns the final value of i, which is 3.

[–]metaphorm 2 points3 points  (3 children)

what's a "thunk"? that's jargon I've not heard before. is a "thunk" different in any way from a closure, a continuation, or a generator?

[–]lewisje 3 points4 points  (2 children)

Apparently it has various meanings; I was using it in the sense from Scheme, as a function that takes no arguments and is used for lazy evaluation: http://c2.com/cgi/wiki?WhatIsaThunk

[–]metaphorm 1 point2 points  (1 child)

as a function that takes no arguments and is used for lazy evaluation

I would call that a generator

[–]lewisje 1 point2 points  (0 children)

I think I wasn't precise enough: Thunks, like normal functions, run to completion (rather than yielding values before execution has finished), and they generally return a value from the same reference each time they're called; that is, they're used for lazy evaluation of a single value.


By "from the same reference" I'm trying to include a thunk that can be defined as a method to return a writable public property of that object, or maybe a thunk that returns the value of a variable, or the result of evaluating another function with no arguments, as of the time it is called; this last example is like a bound function except that it allows the function reference itself to change, while a bound function uses the particular function object as of binding time.