Path: utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!mailrus!ames!pasteur!ucbvax!BASEL.AI.MIT.EDU!lyn From: lyn@BASEL.AI.MIT.EDU (Franklyn Turbak) Newsgroups: comp.lang.scheme Subject: ``Update functions'' in Scheme. Message-ID: <8805031911.AA04352@basel> Date: 3 May 88 19:11:14 GMT References: <411493.880427.SCHREQ@MC.LCS.MIT.EDU> Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 37 > Did anybody already think about adding ``generalized functions'' > (a la Common-Lisp's setf/defsetf feature) to Scheme? This would > eliminate the need for several primitive procedures, among them > set-car!, set-cdr!, vector-set!, and string-set!. Instead of writing > > (set-car! p 5) or (vector-set! v 10 'a) > > this would make it possible to write > > (set! (car p) 5) or (set! (vector-ref v 10) 'a) What's so great about SETF? It doesn't eliminate the *need* for the setting primitives (after all, they conceptually must still be there); it just makes it easier to remember their "names" by providing a convention for deriving the setter from the accessor. But it's easy to develop alternate naming conventions without altering Scheme. One simple convention can be carried out by simple renaming: (define set!car set-car!) (define set!cdr set-cdr!) (define set!vector-ref vector-set!) (define set!string-ref string-set!) Here the name of each setter is the name of the accessor prefixed by set! Now we can write (set!car p 5) or (set!vector-ref v 10 'a) which, except for the missing pair of parens, looks a lot like the SETF approach. And we didn't have to extend Scheme all! - Lyn -