all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: alists
Date: Thu, 27 Mar 2008 00:57:01 -0400	[thread overview]
Message-ID: <barmar-2E7DEF.00570127032008@newsgroups.comcast.net> (raw)
In-Reply-To: uwsnpk5nw.fsf@tiscali.co.uk

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


  reply	other threads:[~2008-03-27  4:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-26 12:53 alists David Roderick
2008-03-27  4:57 ` Barry Margolin [this message]
2008-03-27 14:27   ` alists David Roderick

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=barmar-2E7DEF.00570127032008@newsgroups.comcast.net \
    --to=barmar@alum.mit.edu \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.