From: Shin
Subject: Basic question on modifying cdrs.
Date: 
Message-ID: <49qo7scoiegh9dofmb1a2ennhagpkl36sb@4ax.com>
I would like to know if when one assigns to a variable the cdr of a list
gets the actual cdr, so changing it, no matter how, will change the
whole list.

For instance, provided

   (setq list '(1 3))
   (setq tail (cdr list)) ; Is tail *only* a list or is remembered that
                          ; is the cdr of LIST somehow?

is it sure that after any of the following forms

   o (push 2 tail)
   o (setq tail (cons 2 tail))
   o (setf (cdr list) (cons 2 tail))

LIST will be (1 2 3)? (The implementations I have modify LIST, but I
would like to know if you can take it for granted in Common Lisp.)

Thanks again,

-- Shin

P.D.: I know a bit of C: is there a model in terms of pointers that
would be an aid to understand how this works and solve myself this kind
of doubts?
From: Shin
Subject: Re: Basic question on modifying cdrs.
Date: 
Message-ID: <da9p7ss7l4pjea5rm5k9geg7qs9vmfc262@4ax.com>
On Wed, 12 Jan 2000 13:28:23 +0100, Shin <ยทยทยท@retemail.es> wrote:

: I would like to know if when one assigns to a variable the cdr of a list
: gets the actual cdr, so changing it, no matter how, will change the
: whole list.

I think I have gotten the idea. Provided

   (setq x '(1 3))
   (setq y x)

X and Y become EQ so CAR and CDR when applied to X or Y get to the car and
the cdr of the same object.

By analogy, and if I am not wrong,

   (setq y (cdr x))

gives the cdr of X in the sense that we can get into the cadr and the cddr
of X by means of (CAR Y) and (CDR Y) respectively, but if we modify the
binding of Y as in (SETQ Y 'FOO) this works as usual and has nothing to do
with what X holds.

Now I believe I know how to go down cdr'ing in a safe way.

Thanks anyway,

-- Shin