unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: uzibalqa <uzibalqa@proton.me>
To: Drew Adams <drew.adams@oracle.com>
Cc: Platon Pronko <platon7pronko@gmail.com>,
	uzibalqa via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: RE: [External] : Determine whether a list is an alist
Date: Thu, 13 Jul 2023 15:57:55 +0000	[thread overview]
Message-ID: <NmVeAIqQQ2YUPDg6_9AlFZzpEB1TZQzvBwUqZQeDfAbjfOqv0TyebM8pQmSIxnLfRx4QDQ82ETPXHGKMvR6WYy9dq-PaN5YX6zALp1YbrlQ=@proton.me> (raw)
In-Reply-To: <CO6PR10MB54732C40657E8B3062179A2FF337A@CO6PR10MB5473.namprd10.prod.outlook.com>


------- Original Message -------
On Friday, July 14th, 2023 at 3:40 AM, Drew Adams <drew.adams@oracle.com> wrote:


> > > Every list is an alist.
> > 
> > Can you elaborate? '(1 2 3) is a list, but I don't think it's an
> > association list (at least according to Emacs manual - alist is supposed
> > to be a list of cons cells, which '(1 2 3) definitely isn't).
> 
> 
> Well, yes; and no.
> 
> "In Emacs Lisp, it is not an error if an element of an association list is not a cons cell. The alist search functions simply ignore such elements. Many other versions of Lisp signal errors in such cases." (elisp) `Association Lists'
> 
> (let ((x 5))
> (assoc-default x '(1 2 3 4 5) nil x)) ; => 5
> 
> 
> None of those list elements is a cons.
> 
> (assq 5 '(nil (5 . foo))) ; => (5 . foo)
> 
> 
> Element nil is not a cons.
> 
> ___
> 
> The point is: specify what you really want when
> asking to test whether a list is an alist.
> 
> Even asking whether a Lisp object is a list is
> imprecise - proper/true list or just a nil or
> cons?
> 
> Knowing what you're asking and what you really
> want to ask is the first step (sometimes it's
> even sufficient) toward getting the answer you
> need.
> ___
> 
> And be aware that if you test every element of a
> list then that can be costly. It might in some
> cases be better to just test as you go, while
> you're trying to do something with the alist -
> e.g., while you're looking for an alist element
> match.

Agreed
 
> In many (most?) cases you don't really care
> whether each element of the list is a cons - you
> just want to retrieve the first match, and you
> only want to traverse then entire list if you
> have to (i.e., when there's no match or the last
> element matches), and you don't want to traverse
> it more than once.

If I want to print the alist in (Key . Value) way, how would one skip
extraneous (non-cons) list entries ?



  parent reply	other threads:[~2023-07-13 15:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13 10:40 Determine whether a list is an alist uzibalqa
2023-07-13 14:31 ` [External] : " Drew Adams
2023-07-13 14:40   ` Platon Pronko
2023-07-13 15:40     ` Drew Adams
2023-07-13 15:44       ` Drew Adams
2023-07-13 15:49       ` Platon Pronko
2023-07-13 15:56         ` Drew Adams
2023-07-13 15:57       ` uzibalqa [this message]
2023-07-13 16:06         ` Platon Pronko
2023-07-13 16:14           ` Drew Adams
2023-07-13 16:07         ` Drew Adams
2023-07-13 16:12           ` Robert Pluim
2023-07-13 16:16             ` Drew Adams
2023-07-13 15:59       ` Drew Adams
2023-07-13 14:42   ` uzibalqa

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='NmVeAIqQQ2YUPDg6_9AlFZzpEB1TZQzvBwUqZQeDfAbjfOqv0TyebM8pQmSIxnLfRx4QDQ82ETPXHGKMvR6WYy9dq-PaN5YX6zALp1YbrlQ=@proton.me' \
    --to=uzibalqa@proton.me \
    --cc=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=platon7pronko@gmail.com \
    /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).