Hi. I forgot what function I would use to modify existing data in memory.
For example:
(setf x '( (1 2 3) (a b c) ))
(setf y x)
now y is just a pointer to the data that x points to, right? Well, what
function would allow me to swap, say, "1" and "a"?? I tried to use
replace...but it didn't work. Thanks.
Chester
In article <·················@news.cc.columbia.edu>,
Chester Wong <·····@columbia.edu> wrote:
>Hi. I forgot what function I would use to modify existing data in memory.
(setf <place> <value>) is the general function for modifying what's in
<place>.
>For example:
>
>(setf x '( (1 2 3) (a b c) ))
>(setf y x)
>
>now y is just a pointer to the data that x points to, right? Well, what
>function would allow me to swap, say, "1" and "a"?? I tried to use
>replace...but it didn't work. Thanks.
ROTATEF with two arguments will swap the the contents of the two places:
(rotatef (first (first x)) (first (second x)))
Functions for replacing in particular data types include RPLACA and RPLACD
(for conses), SUBSTITUTE (for sequences), include NSUBST (for trees).
--
Barry Margolin
BBN Corporation, Cambridge, MA
······@bbnplanet.com
(BBN customers, call (800) 632-7638 option 1 for support)
·····@columbia.edu (Chester Wong) writes:
>
> Hi. I forgot what function I would use to modify existing data in memory.
> For example:
>
> (setf x '( (1 2 3) (a b c) ))
> (setf y x)
>
> now y is just a pointer to the data that x points to, right? Well, what
> function would allow me to swap, say, "1" and "a"?? I tried to use
> replace...but it didn't work. Thanks.
>
> Chester
You could do
USER(9): (setf x '( (1 2 3) (a b c) ))
((1 2 3) (A B C))
USER(10): (rotatef (caar x) (caadr x))
NIL
USER(11): x
((A 2 3) (1 B C))
USER(12):
--
Adam P. Jenkins
···············@cs.umass.edu
University of Massachusetts/Amherst
Office Number: (413) 545-3506
In article <·················@news.cc.columbia.edu>, ·····@columbia.edu
(Chester Wong) wrote:
> Hi. I forgot what function I would use to modify existing data in memory.
> For example:
>
> (setf x '( (1 2 3) (a b c) ))
> (setf y x)
>
> now y is just a pointer to the data that x points to, right? Well, what
> function would allow me to swap, say, "1" and "a"?? I tried to use
> replace...but it didn't work. Thanks.
(rotatef (first (first x))
(first (second x)))
--
http://www.lavielle.com/~joswig/