all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* alists
@ 2008-03-26 12:53 David Roderick
  2008-03-27  4:57 ` alists Barry Margolin
  0 siblings, 1 reply; 3+ messages in thread
From: David Roderick @ 2008-03-26 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: alists
  2008-03-26 12:53 alists David Roderick
@ 2008-03-27  4:57 ` Barry Margolin
  2008-03-27 14:27   ` alists David Roderick
  0 siblings, 1 reply; 3+ messages in thread
From: Barry Margolin @ 2008-03-27  4:57 UTC (permalink / raw)
  To: help-gnu-emacs

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 ***


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: alists
  2008-03-27  4:57 ` alists Barry Margolin
@ 2008-03-27 14:27   ` David Roderick
  0 siblings, 0 replies; 3+ messages in thread
From: David Roderick @ 2008-03-27 14:27 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

>> 
>> (car (cdr needles-per-cluster))
>> is (3 . ("Pitch Pine"))
>
> Do you have a question here?

No, I was clarifying the same hypothesis again. Thanks.

DR



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-03-27 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-26 12:53 alists David Roderick
2008-03-27  4:57 ` alists Barry Margolin
2008-03-27 14:27   ` alists David Roderick

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.