[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re : set in Scheme
Here's my invaluable ;-) comment about _set_ in Scheme. As it is fairly easy
to build up a case for loss of program readability with the addition of _set_
(as opposed to _set!_), we should perhaps be pleased that it is probably
impossible (with macros, extend-syntax, what-not) to define _set_ in Scheme.
The most "correct" version of _set_ in terms of _set!_ given on the net,
(herein transliterated to extend-syntax) is probably
(extend-syntax (set)
[(set x y) (eval (list 'set! x (quote y)))]).
However, Scheme does not offer 'eval' to the user. The most it does is offer
a *global* eval, which ain't the same thing. So,
(define x 0)
==> x
(define y 'x)
==> y
(let ([x 1])
(let ([y 'x])
(set y 2)
x))
==> 1 {instead of 2}
x
==> 2 {instead of 0}
Continuing { with global x = 2, y = x }
(define z 3)
==> z
(let ([z 4])
(set y z)
x)
==> 3 {instead of 4}
The second problem can be appeased by evaluating the settend (to coin a
word) beforehand as in,
(extend-syntax (set)
[(set x y) (begin (set! |weird-identifier| y)
(eval (list 'set! x (quote |weird-identifier|))))])
{|weird-identifier| HAS to be a global variable, because of the globalness
of eval.}
But the first problem remains. A modified version of the second problem can
occur if there are _set_'s inside the settee (to coin a not-so-new word), as
in
(set (set <blah> <foo>) <hukares>)
Any amount of tweaking the extend-syntax for set, seems destined to lead
nowhere. That, as they (and Magnum) say, is "the hell of it".
--dorai