[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Writing Destructive Functions
- To: info-mcl@cambridge.apple.com, jbk@world.std.com, york@oakland-hills.lucid.com
- Subject: Re: Writing Destructive Functions
- From: Ranson <ranson@LANNION.cnet.fr>
- Date: 30 Sep 92 07:53:00 GMT
- Cc: ranson@lannion.cnet.fr
- X400-received: by /PRMD=inria/ADMD=atlas/C=FR/; Relayed; 30 Sep 92 07:53:13+0100
- X400-received: by /PRMD=CNET/ADMD=ATLAS/C=FR/; Relayed; 30 Sep 92 07:53:00 GMT
Here is a function that has the requested behaviour:
(defun replace-first (l new)
(setf (cdr l) (cons (car l) (cdr l))
(car l) new))
That is, you add a cons cell after the first one, move the first element to
the second place, and add the new elemnt in its place.
This may not work if you share other parts of the list too.
Daniel.