unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: predicates on lists
Date: Thu, 27 Mar 2008 01:07:04 -0400	[thread overview]
Message-ID: <barmar-1E4F44.01070427032008@newsgroups.comcast.net> (raw)
In-Reply-To: u1w5xllsb.fsf@tiscali.co.uk

In article <u1w5xllsb.fsf@tiscali.co.uk>,
 David Roderick <angel_ov_north@tiscali.co.uk> wrote:

> Elisp 5.8
> 
>  -- Function: assoc-default key alist &optional test default
>      This function searches ALIST for a match for KEY.  For each
>      element of ALIST, it compares the element (if it is an atom) or
>      the element's CAR (if it is a cons) against KEY, by calling TEST
>      with two arguments: the element or its CAR, and KEY.  The
>      arguments are passed in that order so that you can get useful
>      results using `string-match' with an alist that contains regular
>      expressions (*note Regexp Search::).  If TEST is omitted or `nil',
>      `equal' is used for comparison.
> 
> I am a bit confused. I thought that an element inside of an associated
> list is a dotted pair of its CAR and CDR, and the KEY is the CAR.  The
> argument as key in the above function confused me.  Having solved this

The above function allows "singletons" to be elements of the alist, in 
addition to associations.  In that case, it treats the element as its 
own key.

> problem, and realizing that this function is complicated, am I correct
> in thinking that an atom is   (atom OBJECT) == (not (consp OBJECT))
> This is confusing because an atom is a fundamental building block
> outside of Elisp, and a cons cell is a fundamental building block by
> Elisp.
> It seems that anything which is not a cons cell should be a molecule.

The original meaning of "atom" is something that can't be split into 
pieces.  And in early versions of Lisp, conses were the only data types 
that had multiple components, so they used the term "atom" to refer to 
everything else.

> Ok, now that I have got this silly questioning over and done with, a
> further query arises in my brain.
> 
>      you can get useful
>      results using `string-match' with an alist that contains regular
>      expressions (*note Regexp Search::).  
> 
> Does the string-match contain a regular expression or does the alisp
> contain a regular expression?

String-match is a function.  What do you mean by "string-match contain a 
regular expression"?  I think you're asking whether KEY would contain 
the regular expression.  And if they meant that, they would have said it 
rather than "alist that contains regular expressions".

> My guess is the string-match may contain a regular expression, but 
> this process of deduction might be
> eliminated if the explanation was revised.

It's saying that the alist has regular expressions as the keys.  A 
well-known example is auto-mode-alist, which is an alist mapping regular 
expressions to major modes.  It gets used as:

(assoc-default filename auto-mode-alist 'string-match)

-- 
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  5:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-26 12:20 predicates on lists David Roderick
2008-03-27  5:07 ` Barry Margolin [this message]
2008-03-27 14:43   ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=barmar-1E4F44.01070427032008@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).