Path: utzoo!attcan!uunet!husc6!rice!titan!dorai From: dorai@titan.rice.edu (Dorai Sitaram) Newsgroups: comp.lang.scheme Subject: Re: Re : set in Scheme Summary: set is not possible (perhaps rightly so) in your favorite language Keywords: set, set!, eval, Scheme Message-ID: <683@thalia.rice.edu> Date: 10 May 88 15:41:48 GMT References: <12073@shemp.CS.UCLA.EDU> Sender: usenet@rice.edu Reply-To: dorai@titan.UUCP (Dorai Sitaram) Distribution: na Organization: Rice University, Houston Lines: 55 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 ) ) 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