[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
letrec and set!
Date: Thu, 19 Aug 93 18:05:10 +0200
From: Christian Queinnec <Christian.Queinnec@inria.fr>
Reply-To: Christian.Queinnec@inria.fr
(letrec ((x (begin (set! y 1)
y ))
(y 3) )
x ) ---> 1
But if letrec is operationally explained by a let with inner
assignments, the way it is actually in r4rs, what is the reason to
forbid writing to a mutually defined variable, nor it is necessary to
require a "smart" compiler.
No, the ``operational'' explanation is NOT the definition -- it only explains
the sematics of letrec as long as there is no violation of the rules.
One of these rules is the one that you are questioning.
> (letrec ((x (begin (assign-to-cell! y 1) (refer-to-cell y)))
> (y (make-cell 3)))
> x)
Incidently I see the box model (or value cell) without explicit
initialization so I see the program fragment more like:
(let ((x (create-box))
(y (create-box)) )
; `let' to keep undeterminacy
(let ((void1 (box-set! x (begin (box-set! y 1) (box-ref y))))
(void2 (box-set! y 3)) )
(box-ref x) ) )
Indeed, this is a correct transformation. But I claim that my
(shorter and more efficient) transformation would also be correct
PROVIDED that the rules are obeyed (which they are not in the example
program fragment).
-Matthias