Re: Making alistp matching plistp requirements

Heime <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <3qD8uTN0uuJPKaGKWhTrNqSQ34ciSB1-wKBlKYzHtQ91opOg_LvTBIff2XZp1ANeQgxgoZ2Op0dsF23KPTfR7q01eX0bQ-A_s-qKMpPNpig=@protonmail.com>
On Monday, April 13th, 2026 at 9:59 AM, tpeplt <[email protected]> wrote:

> Heime <[email protected]> writes:
> 
> > plistp is defined as
> >
> > (defun plistp (object)
> >   "Non-nil if and only if OBJECT is a valid plist."
> >   (declare (pure t) (side-effect-free error-free))
> >   (let ((len (proper-list-p object)))
> >     (and len (zerop (% len 2)))))
> >
> > For an equivalent alistp, checking cons cells with key and value,
> > how would the function be?
> >
> 
> The answer is going to depend on how strict you want your
> definition of an association list to be.
> 
> Here is a simple definition that does not check the contents
> of the items in the alist:
> 
>   (defun alistp (obj-list)
>     "Determine whether OBJ-LIST is an association list.
>      This function definition says that an empty list is not
>      an association list."
>     (when (and obj-list (proper-list-p obj-list))
>       (cl-every #'consp obj-list)))
> 
> You might decide to have additional, more strict conditions,
> in which case you could replace ‘#'consp’ with
> ‘#'your-alist-item-p’.
> 
>    (defun your-alist-item-p (pair)
>       (and (consp pair)
>            ... ;; your additional conditions))
> 
> For example, (a . nil) and (a) are the same, so they are a
> valid key/value pair, but you might want to restrict your
> alist pairs not to include nil as a possible value; likewise
> with not allowing nil as a key: (nil . some-value)

Emacs Lisp plistp allows nil as both keys and values.  
Have been thinking of keeping with same idea to accept
nil.
 
> --
> The lyf so short, the craft so long to lerne.
> - Geoffrey Chaucer, The Parliament of Birds.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.