no continuations

oleg at oleg at
Thu Jan 1 21:16:25 EST 2004

Kevin S. Millikin wrote:
> It sure looks like the example contradicts the assertion, but I happen 
> to know that there is a set! (or some other assignment) in the macro 
> expansion of define.  I'm just using call/cc to get at that, rather 
> than getting at the one in the expansion of letrec.

In Scheme 'define' is normally a primitive because in most of the
systems a top-level 'define' must create a top-level variable binding,
and there is no other R5RS form that can do that. Still, you're right
about set!. R5RS says:

"5.2.1. Top level definitions
At the top level of a program, a definition
     (define variable  expression)
has essentially the same effect as the assignment expression
     (set! variable  expression)
if variable is bound. If variable is not bound, however, then the
definition will bind variable to a new location before performing the
assignment...  Some implementations of Scheme use an initial
environment in which all possible variables are bound to locations,
most of which contain undefined values. Top level definitions in such
an implementation are truly equivalent to assignments."

Similarly, R5RS obligates any Scheme implementation to resort to
assignments when processing a letrec form. An implementation may not
use a (polyvariadic) Y to implement letrec, unless the implementation
can prove that the difference is unobservable for the form in
question. Incidentally, one can easily observe how letrec is
implemented. For example, in Ocaml, the observation says that "let rec"
is implemented via an assignment.

So, in the examples mentioned earlier, call/cc simply pries open the
assignment that was already present in letrec or define. Alone,
call/cc cannot emulate assignments. There was a message exactly on the
same topic "call/cc is insufficient to emulate set!"  posted on
comp.lang.scheme two years ago:


might also be useful.

More information about the Haskell-Cafe mailing list