Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!dgr From: dgr@hpfcso.HP.COM (Dave Roberts) Newsgroups: comp.lang.scheme Subject: Re: Re: Virtues of Lisp syntax [for extension languages] Message-ID: <10340003@hpfcso.HP.COM> Date: 24 Sep 90 15:07:49 GMT References: Organization: Hewlett-Packard, Fort Collins, CO, USA Lines: 86 moore%cdr.utah.edu@cs.utah.edu (Tim Moore) writes: > In article <20692@well.sf.ca.us> jjacobs@well.sf.ca.us (Jeffrey Jacobs) writes: > > > >Larry Masinter wrote: > >>>>[As a side note, many learning LISP programmers frequently do > >>>> encounter self-modifying code and are mystified by it, e.g., > >>>> (let ((var '(a b c))) > >>>> ... > >>>> (nconc var value)) > ... > >And Tim Moore wrote: > ... > >>>It's not legal Common > >>>Lisp code, because the constant may be in read-only memory. > > > >Correct me if I'm wrong, but it seems to me that this *is* legal and > >that the compiler should specifically *not* allocate quoted lists such > >as that to read-only memory! > > For better or worse, this is from CLtL2, pg 115: > X3J13 [the body specifying ANSI Common Lisp] voted in January 1989 to > clarify that it is an error to destructively modify any object that > appears as a constant in executable code, whether within a quote > special form or as a self-evaluating form. > > I'm not sure where this was specified in the orginal CLtL; obviously > it wasn't specified too clearly or X3J13 wouldn't have needed to > clarify this point. Umm... I don't want to stick my head into a CL discussion, but this is a Scheme group, or so I though :-). This is supposed to be technically illegal in Scheme, too, right? I mean, you're not supposed to mutate a constant. What I'm curious about is what exactly constitutes mutation? The following is legal; correct? (let ((label '(a b c))) (set! label (append label '(d e f)))) Here I'm just messing with the symbol's definition, not with the actual structure of the constant (...I think, since labels are always handled the same way and it's the actual data that isn't) Now it's definitely illegal to do the following, right? (let ((label '(a b c))) (set-cdr! label '(d e))) I guess my basic question is ``What part of the structure aren't I supposed to mess with, and what if I use a constant to make another structure? Is the resulting structure still a constant?'' IE. is the following okay? (let ((label (append '(a b c) '(d e f)))) (set-cdr! label '(x y z))) How about stuff built up with quasiquote? Help!! I'm really confused about this whole thing. :-) I have this attitude that I don't want to mess with anything that I might have build up from a constant, but I may be overly cautious. How does a procedure that does mutation on its arguments know if the arguments are actually constants or not? When a procedure call is actually done, the call is done by reference, not by value, for complex structures (ie. lists), right? (define x '(a b c)) (define (proc some-list) (set-car! some-list '(d e))) Now, (proc x) should be an error, right, because the symbol some-list isn't bound to a copy of what x contains, but rather to exactly what x is bound to (the original copy of '(a b c)), which I am supposedly not allowed to mess with. Could someone who knows what's going on lend me some intelligence? Thanks. Dave Roberts Hewlett-Packard Co. dgr@hpfcla.fc.hp.com