* predicates on lists
@ 2008-03-26 12:20 David Roderick
2008-03-27 5:07 ` Barry Margolin
0 siblings, 1 reply; 3+ messages in thread
From: David Roderick @ 2008-03-26 12:20 UTC (permalink / raw)
To: help-gnu-emacs
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
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.
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?
My guess is the string-match may contain a regular expression, but
this process of deduction might be
eliminated if the explanation was revised.
--
from
David Roderick
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: predicates on lists
2008-03-26 12:20 predicates on lists David Roderick
@ 2008-03-27 5:07 ` Barry Margolin
2008-03-27 14:43 ` David Roderick
0 siblings, 1 reply; 3+ messages in thread
From: Barry Margolin @ 2008-03-27 5:07 UTC (permalink / raw)
To: help-gnu-emacs
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 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-27 14:43 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:20 predicates on lists David Roderick
2008-03-27 5:07 ` Barry Margolin
2008-03-27 14:43 ` David Roderick
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).