[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sharing list structure
From: |
Denis Bueno |
Subject: |
Re: sharing list structure |
Date: |
Thu, 24 Mar 2005 19:35:50 -0500 |
On Thu, 24 Mar 2005 18:27:28 -0600, Joe Corneli
<jcorneli@math.utexas.edu> wrote:
> The `append' doesn't alter the structure of the list A.
>
> (defvar *foo* (list 1 2 3))
> (append *foo* (list 4 5 6))
> *foo* => (1 2 3)
>
> Hence, the result of append doesn't alter A's structure.
>
> Note the `setq' above, which make it look an awful lot like the
> structure of A *is* being modified. I mean, it comes out as a
> different list --
The setq modifies what the value of the symbol A is - it's destructive
in that sense. After the setq, instead of being (1 2 3), A's value to
the list (1 2 3 4). But it's a different list (in memory) from its
former value.
> So, just restrict yourself to destructive operations on A - like
> setcdr, setcar, etc. - and you'll be set. Just note that A will always
> have to be the "tail" part of B.
>
> OK, I think I've got the idea now. But still, I'm surprised that `setq'
> is not among the list of "destructive functions". What's that about?
Like I said, the difference is in just _what_ it's destructively
modifying. In the case above, it destructively modifies the value of
the symbol A (see `symbol-value'), not the structure of the list whose
head cons cell is the value of the symbol A (which is just a more
precise way of saying "the list A").
--
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index