Discussion:
parameterize
Joo ChurlSoo
2011-01-13 07:18:20 UTC
Permalink
The following seems to be a bug.
,open srfi-39
(let ((f (make-parameter 'a))
(path '())
(g (make-parameter 'g))
(c #f))
(let ((add (lambda () (set! path (cons (f) path)))))
(add)
(parameterize ((f 'b)
(g (call-with-current-continuation (lambda (c0) (set! c c0) 'c))))
(add) (f (g)) (add))
(f 'd)
(add)
(if (< (length path) 5)
(c 'e)
(reverse path))))
'(a b c d c e d) ;(a b c d b e d)
;; cf.
(let ((f (make-parameter 'a))
(path '())
(g (make-parameter 'g))
(c #f))
(let ((add (lambda () (set! path (cons (f) path)))))
(add)
(parameterize ((f 'b))
(g (call-with-current-continuation (lambda (c0) (set! c c0) 'c)))
(add) (f (g)) (add))
(f 'd)
(add)
(if (< (length path) 5)
(c 'e)
(reverse path))))
'(a b c d c e d)
--
Joo ChurlSoo
Michael Sperber
2011-01-14 07:23:58 UTC
Permalink
Post by Joo ChurlSoo
The following seems to be a bug.
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.
--
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
Taylor R Campbell
2011-01-14 15:55:12 UTC
Permalink
Date: Fri, 14 Jan 2011 08:23:58 +0100
From: Michael Sperber <***@deinprogramm.de>

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.)
Michael Sperber
2011-01-15 13:11:34 UTC
Permalink
Post by Taylor R Campbell
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 () ...))).
Yes - I've pushed a fix that does this. Thanks for the explanation!
Post by Taylor R Campbell
(You could also throw up your hands and say `mutable parameters are
bunk'
Indeed!
--
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla
Joo ChurlSoo
2011-01-15 09:34:38 UTC
Permalink
* From: Michael Sperber <***@deinprogramm.de>
* Date: Fri, 14 Jan 2011 08:23:58 +0100
* Subj: Re: parameterize
Post by Joo ChurlSoo
The following seems to be a bug.
| 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.

(cf.)
(let ((go #f)
(alist '()))
(let ((a 1) (b 2))
(call-with-current-continuation (lambda (x) (set! go x) 3))
(set! alist (cons (cons a b) alist))
(set! a 100)
(set! alist (cons (cons a b) alist))
(if (< (length alist) 3)
(go 3)
(reverse alist))))

((1 . 2) (100 . 2) (100 . 2) (100 . 2))

(let ((go #f)
(alist '()))
(let ((a 1) (b (call-with-current-continuation (lambda (x) (set! go x) 2))))
(set! alist (cons (cons a b) alist))
(set! a 100)
(set! alist (cons (cons a b) alist))
(if (< (length alist) 3)
(go 2)
(reverse alist))))

((1 . 2) (100 . 2) (1 . 2) (100 . 2))

| --
| Cheers =8-} Mike
| Friede, Völkerverständigung und überhaupt blabla
--
Joo ChurlSoo
Loading...