Re: Making alistp matching plistp requirements
tpeplt <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <[email protected]> |
Heime <[email protected]> writes: > On Monday, April 13th, 2026 at 9:59 AM, tpeplt <[email protected]> wrote: > >> >> 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))) > > Emacs Lisp plistp allows nil as both keys and values. > Have been thinking of keeping with same idea to accept > nil. > That is a simple change to the definition, above: (defun alistp (obj-list) "Determine whether OBJ-LIST is an association list." (when (proper-list-p obj-list) (cl-every #'consp obj-list))) Be aware that you may need code to distinguish between a value set to nil in an alist and an empty alist: (alist-get 'a '((a . nil))) ;;=> nil (alist-get 'a '()) ;;=> nil -- The lyf so short, the craft so long to lerne. - Geoffrey Chaucer, The Parliament of Birds.