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 14:32:33 +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="2681"; 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 16:33:27 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 1sqZGg-0000RD-Mo for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 17 Sep 2024 16:33:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqZG3-000452-DH; Tue, 17 Sep 2024 10:32:47 -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 1sqZG1-00044t-KQ for help-gnu-emacs@gnu.org; Tue, 17 Sep 2024 10:32:46 -0400 Original-Received: from mail-40141.protonmail.ch ([185.70.40.141]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqZFw-0001RC-BY for help-gnu-emacs@gnu.org; Tue, 17 Sep 2024 10:32:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1726583557; x=1726842757; bh=SQzvWk78S0VO2800PfUUOP/wYevyDLnKFMQupcdRK4Q=; 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=SsDRJv859tBpNCi8iyINbfK+W7RHX7dmwrvX7TNEVxLpYfBXgnSNpLmN/Q9wwBBHY owDm42S5n82fi0JLgoFFvbS3y9I/prbk3RKCFRbByOimNfuFCy5pFdT7gmlVd+TizY 8BomFVStfXkWrMDkf/CN2Pfbv9xR9xfh5Qs7bkmSs8Eis8OZM+jLsgZDWfAYZ/fqfF B+sNZdP+mGvdRvLz4yHJ/N43k30/UIrN9uyQkyqv6elPU8AvEy0hqZ8uhJIx/nZr27 ExZLRQetXI5MGA+/5AfYN9zwV44v64w2rf4mlU10g7xTnsnLSPeZOxYJ1No8+IHz5U JyRDN/Js+FUQg== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: d7464dd4a492042530fda8039bd04272026cc280 Received-SPF: pass client-ip=185.70.40.141; envelope-from=heimeborgia@protonmail.com; helo=mail-40141.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:148006 Archived-At: On Wednesday, September 18th, 2024 at 1:58 AM, tomas@tuxteam.de wrote: > On Tue, Sep 17, 2024 at 01:51:54PM +0000, Heime wrote: >=20 > [...] >=20 > > Have modified the code to this > >=20 > > (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))) > >=20 > > I want to allow empty lists and empty keys. Or should I remove (null x) > > as well ? >=20 >=20 > That depends on how strict you want to be. Have you read elisp's > docs on association lists? >=20 > Elisp tends to tolerate alists whose elements are not pairs. Other > Lisps are stricter. Your function is a funny in-between (nil non-pairs > are OK, but others are not). >=20 > First try to understand what you are trying to do, then do. Note that, > contrary to hashes, alists are not strictly defined. >=20 > Cheers > -- > t Originally I tried to find something as alistp but did not find any. I wou= ld have stayed to what it would have allowed. But then I started writing my o= wn. For what I am doing, there is always a key and value in each cell. =20 But taking in consideration what others have been saying here about alists,= I=20 decided to be more flexible and allow empty alists and keys with nil. Then (null x) should not be there because it allows nil non-pairs. This is what I am trying to do with (defun torium-alist-p (obj) "Return t if object OBJ is an association list (alist). An alist=20 can be empty and nil can act as a key." (and (listp obj) (every (lambda (x) (or (null x) (consp x))) obj)))