[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
alists
From: |
David Roderick |
Subject: |
alists |
Date: |
Wed, 26 Mar 2008 12:53:39 +0000 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (windows-nt) |
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?
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"))
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
--
from
David Roderick
- alists,
David Roderick <=