From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Check whether an object is an alist Date: Tue, 17 Sep 2024 13:51:54 +0000 Message-ID: References: <87wmjamxg9.fsf@ledu-giraud.fr> <5ta65eMG2v0q4BbBDFQ5D7JUEXbXaBCpR3DOxm2lsGJpx-9k04kvX-UFtQTaKRvUEK6Pi7vP2q_0JrADs7MB8JIL4jzAZFEQHQf1enrBLtM=@protonmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36396"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 17 15:52:34 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sqYd8-0009Me-5u for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 17 Sep 2024 15:52:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqYcf-0004Pp-I7; Tue, 17 Sep 2024 09:52:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqYcd-0004Pf-Ve for help-gnu-emacs@gnu.org; Tue, 17 Sep 2024 09:52:04 -0400 Original-Received: from mail-43167.protonmail.ch ([185.70.43.167]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqYcc-00051d-8X for help-gnu-emacs@gnu.org; Tue, 17 Sep 2024 09:52:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1726581119; x=1726840319; bh=A5jqP/yU/ty6VdJcTJgr5lGb3BB0hFKb9L11+0+5qu8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=DRW3Af7NU21DJcPrTsTldG90RLH+JfbWSR5ZXLFURJMUUIMlHiUK6DzmCBAYdmq+b n0R7qeGwHI24mNX6tckfVtCFZIXwTcgPL3t8ngL/B+HyarxjvYi9ifN+6ETxBAeMyZ IaaqGVG6YmyzGYHJR2SYlqVjjw8+MpNzAaKEz7vdmWIsVk0UmWJiPs9ZFr2kMWXEie i/MhjhS5YCiOXXznInUQ/1mleQoTPVOfHc59SgpQQRcD0wFBuKECfABQJLS1Dq2GG4 5HMzPotNPM3VGv0r+E7cCtekRGSTBg+5mhvkkUMt4ZxtHwFgmIqQxkUU1MW+ERMEIT YMu7p/s1WjcSA== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 3550076daac20f1e78b3af7759d490f102a84a94 Received-SPF: pass client-ip=185.70.43.167; envelope-from=heimeborgia@protonmail.com; helo=mail-43167.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148004 Archived-At: On Tuesday, September 17th, 2024 at 11:23 PM, tomas@tuxteam.de wrote: > On Tue, Sep 17, 2024 at 11:16:24AM +0000, Heime wrote: >=20 > > Sent with Proton Mail secure email. > >=20 > > On Tuesday, September 17th, 2024 at 9:46 PM, tomas@tuxteam.de tomas@tux= team.de wrote: > >=20 > > > On Tue, Sep 17, 2024 at 11:38:46AM +0200, Manuel Giraud via Users lis= t for the GNU Emacs text editor wrote: > > >=20 > > > > Heime heimeborgia@protonmail.com writes: > > > >=20 > > > > > Sent with Proton Mail secure email. > > > > >=20 > > > > > On Monday, September 16th, 2024 at 10:29 PM, Heime heimeborgia@pr= otonmail.com wrote: > > > > >=20 > > > > > > Is there a function that checks whether an object is an alist. > > > > > > Have only found listp. > > > > >=20 > > > > > Because I may have to come up with a solution, I have made this o= ne. > > > > > Am I missing anything ? > > > > >=20 > > > > > (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))) > > > >=20 > > > > Looks good to me. I think it should `cl-every' instead of` every' a= nd > > > > also, maybe, nil is a valid empty alist. > > >=20 > > > Unless you'd like to have nil as a possible key (alists allow that, > > > why not?): > > >=20 > > > (setq al '((nil . "I am not") (t . "I am"))) > > > (alist-get nil al) > > > =3D> "I am not" >=20 >=20 > 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. >=20 > Cheers > -- > t 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 ?