[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 13:23:17 +0200 |
On Tue, Sep 17, 2024 at 11:16:24AM +0000, Heime wrote:
>
>
>
>
>
> Sent with Proton Mail secure email.
>
> On Tuesday, September 17th, 2024 at 9:46 PM, tomas@tuxteam.de
> <tomas@tuxteam.de> wrote:
>
> > On Tue, Sep 17, 2024 at 11:38:46AM +0200, Manuel Giraud via Users list for
> > the GNU Emacs text editor wrote:
> >
> > > Heime heimeborgia@protonmail.com writes:
> > >
> > > > Sent with Proton Mail secure email.
> > > >
> > > > On Monday, September 16th, 2024 at 10:29 PM, Heime
> > > > heimeborgia@protonmail.com wrote:
> > > >
> > > > > Is there a function that checks whether an object is an alist.
> > > > > Have only found listp.
> > > >
> > > > Because I may have to come up with a solution, I have made this one.
> > > > Am I missing anything ?
> > > >
> > > > (defun torium-alist-p (obj)
> > > > "Return t if object OBJ is an association list (alist)."
> > > > (and (listp obj)
> > > > (not (null obj))
> > > > (every (lambda (x)
> > > > (and (consp x)
> > > > (not (null x))))
> > > > obj)))
> > >
> > > Looks good to me. I think it should `cl-every' instead of` every' and
> > > also, maybe, nil is a valid empty alist.
> >
> >
> > Unless you'd like to have nil as a possible key (alists allow that,
> > why not?):
> >
> > (setq al '((nil . "I am not") (t . "I am")))
> > (alist-get nil al)
> > => "I am not"
Oh, wait. I just see you were checking the pair to be not
null. Then it's easier: your above code seems right, just
the (not (null x)) is superfluous, since (consp x) makes
sure it is so.
Cheers
--
t
signature.asc
Description: PGP signature
- Check whether an object is an alist, Heime, 2024/09/16
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist, Manuel Giraud, 2024/09/17
- Re: Check whether an object is an alist, tomas, 2024/09/17
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist,
tomas <=
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist, tomas, 2024/09/17
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist, tomas, 2024/09/17
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist, tomas, 2024/09/17
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist, tomas, 2024/09/17
- Re: Check whether an object is an alist, Heime, 2024/09/17
- Re: Check whether an object is an alist, tomas, 2024/09/17