Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!seismo!sundc!newstop!sun!basselope!shiffman From: shiffman%basselope@Sun.COM (Hank Shiffman) Newsgroups: comp.lang.lisp Subject: Re: Are "destructive" functions really destructive? Message-ID: <128536@sun.Eng.Sun.COM> Date: 29 Nov 89 17:37:53 GMT References: <20991@mimsy.umd.edu> Sender: news@sun.Eng.Sun.COM Reply-To: shiffman@sun.UUCP (Hank Shiffman) Distribution: usa Organization: Sun Microsystems, Mountain View Lines: 40 In article <20991@mimsy.umd.edu> folta@tove.umd.edu (Wayne Folta) writes: >For example, if I want to delete something from a large datastructure, I >assume that I would use "delete": > > (delete item huge-list :key #'my-key) > >Or do I need to do: > > (setq huge-list (delete item huge-list :key #'my-key)) Either one of these will work AS LONG AS THE DELETED ITEM WASN'T THE FIRST ELEMENT OF THE LIST! You need to use the second version to deal with the fact that using DELETE to remove the first element leaves the rest of the list unchanged. Since the deleted element will not be modified, it will still point to the rest of the list. DELETE is a function. By the time it's called, the HUGE-LIST argument has been evaluated to the first CONS in the list. DELETE can't do the SETQ for you, since it doesn't know what variable to SETQ. > >So destructiveness is an option for the convenience of LISP >implementation creators, not users? > On the contrary. Destructiveness saves the user a lot of extra consing by reusing the same list. By and large, ease of implementation was *not* a major consideration in the design of Common Lisp. And it shows. -- Hank Shiffman (415) 336-4658 Marketing Technical Specialist Software Engineering Technologies ...!sun!shiffman Sun Microsystems, Inc. shiffman@Sun.com Zippy sez: Do you have exactly what I want in a plaid poindexter bar bat??