Re: Making alistp matching plistp requirements

Heime <[email protected]>
Newsgroups gmane.emacs.help
Message-ID <DrbUftXA3ts6Qtoc7GBpw9fiVBPm7iemIRK7CTMV6vDowt0CHRF-G5ATyQ4y3XDeOuGfDAcWT0-JaRUxVtCuSGJswou4gFTOUudxY64T3cY=@protonmail.com>
On Monday, April 13th, 2026 at 10:55 AM, tpeplt <[email protected]> wrote:

> 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

Have come up with this

(defun lana-alistp (object)
  (declare (pure t) (side-effect-free error-free))
  (cond ((atom object)  (eq object nil))
        (t  (and (consp (car object))
                 (lana-alistp (cdr object))))))

How do you think this compares with your version?
 
> --
> 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.