help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check whether an object is an alist


From: tomas
Subject: Re: Check whether an object is an alist
Date: Tue, 17 Sep 2024 15:58:59 +0200

On Tue, Sep 17, 2024 at 01:51:54PM +0000, Heime wrote:

[...]

> Have modified the code to this
> 
> (defun torium-alist-p (obj)
>   "Return t if object OBJ is an association list (alist)."
>   (and (listp obj)
>        (every (lambda (x)
>                 (or (null x)
>                     (consp x)))
>               obj)))
> 
> I want to allow empty lists and empty keys.  Or should I remove (null x)
> as well ?

That depends on how strict you want to be. Have you read elisp's
docs on association lists?

Elisp tends to tolerate alists whose elements are not pairs. Other
Lisps are stricter. Your function is a funny in-between (nil non-pairs
are OK, but others are not).

First try to understand what you are trying to do, then do. Note that,
contrary to hashes, alists are not strictly defined.

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]