[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: alists
From: |
Barry Margolin |
Subject: |
Re: alists |
Date: |
Thu, 27 Mar 2008 00:57:01 -0400 |
User-agent: |
MT-NewsWatcher/3.5.3b2 (Intel Mac OS X) |
In article <uwsnpk5nw.fsf@tiscali.co.uk>,
David Roderick <angel_ov_north@tiscali.co.uk> wrote:
> Elisp 5.8
> -- Function: copy-alist alist
> This function returns a two-level deep copy of ALIST: it creates a
> new copy of each association, so that you can alter the
> associations of the new alist without changing the old one.
>
> (setq needles-per-cluster
> '((2 . ("Austrian Pine" "Red Pine"))
> (3 . ("Pitch Pine"))
> (5 . ("White Pine"))))
> =>
> ((2 "Austrian Pine" "Red Pine")
> (3 "Pitch Pine")
> (5 "White Pine"))
>
> (setq copy (copy-alist needles-per-cluster))
> =>
> ((2 "Austrian Pine" "Red Pine")
> (3 "Pitch Pine")
> (5 "White Pine"))
>
> (eq needles-per-cluster copy)
> => nil
> (equal needles-per-cluster copy)
> => t
> (eq (car needles-per-cluster) (car copy))
> => nil
> (cdr (car (cdr needles-per-cluster)))
> => ("Pitch Pine")
>
> I don't understand how the cdr of one element in the alist in connected
> with the next cons cell.
> The first cons cell has a CDR of "Austrian Pine" "Red Pine".
> In what way does this contain a reference to the next list (3.("Pitch
> Pine"))?
> Is there an outer level of a sequence happening?
> Yes, an outer list.
> So (2 . ("Austrian Pine" "Red Pine")) is actually the CAR of an outer
> cons cell which has (3 . ("Pitch Pine")) as its CDR.
> Is this correct?
Correct. That outer cons cell is the alist itself. Its elements are
the individual associations.
>
> 2.3.6.2 Dotted Pair Notation
> ............................
> In dotted pair
> notation, the list `(1 2 3)' is written as `(1 . (2 . (3 . nil)))'
>
> (car (cdr needles-per-cluster))
> is (3 . ("Pitch Pine"))
Do you have a question here?
>
> ELISP can be HEAVY GOING
>
> Elisp 5.3
> -- Function: cdr cons-cell
> This function returns the value referred to by the second slot of
> the cons cell CONS-CELL. Expressed another way, this function
> returns the CDR of CONS-CELL.
>
> As a special case, if CONS-CELL is `nil', then `cdr' is defined to
> return `nil'; therefore, any list is a valid argument for `cdr'.
> An error is signaled if the argument is not a cons cell or `nil'.
>
> (cdr '(a b c))
> => (b c)
> (cdr '())
> => nil
Again, what's your question?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
- alists, David Roderick, 2008/03/26
- Re: alists,
Barry Margolin <=