Re: parameterize

Taylor R Campbell <[email protected]> Fri, 14 Jan 2011 15:55:12 +0000
Newsgroups gmane.lisp.scheme.scheme48
Message-ID <[email protected]>
   Date: Fri, 14 Jan 2011 08:23:58 +0100
   From: Michael Sperber <[email protected]>

   Could you elaborate?  I enjoy analyzing intricate uses of
   `call-with-current-continuation' as much as the next person, but am a
   little short on time right now.

The form

(parameterize ((f 'b) (g (cwcc ...))) ...)

expands roughly to the procedure call

(let-fluids f (make-cell 'b) g (make-cell (cwcc ...))
  (lambda () ...)).

Suppose Scheme48 evaluates the operand expressions left-to-right.
Let's say the value of (make-cell 'b) is called c.  Then when Scheme48
evaluates (make-cell (cwcc ...)), the continuation captured will call
MAKE-CELL and pass f, c, g, the new cell, and the thunk to LET-FLUIDS.
This happens both the first time around, before the program modifies
c, and the second time around, after the program modifies c -- thus, f
is bound again to the modified cell, not to a cell containing the
symbol B.

Instead, the continuation captured should call MAKE-CELL twice and
pass f, its new cell, g, its new cell, and the thunk to LET-FLUIDS.
You could effect this by making PARAMETERIZE expand roughly to

(let ((fv 'b) (gv (cwcc ...)))
  (let-fluids f (make-cell fv) g (make-cell gv)
    (lambda () ...))).

(You could also throw up your hands and say `mutable parameters are
bunk' and wonder why anybody ever wants to use them instead of
immutable parameters together with either thread-local cells or
thread-global cells, but I guess that's hard to fix within Scheme48.)