From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Platon Pronko Newsgroups: gmane.emacs.help Subject: Re: [External] : Determine whether a list is an alist Date: Thu, 13 Jul 2023 18:49:51 +0300 Message-ID: References: <7d67c066-c4d7-a568-4dcf-ddfc6b1918fc@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40680"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: Drew Adams , uzibalqa , uzibalqa via Users list for the GNU Emacs text editor Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jul 13 17:50:40 2023 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 1qJyaV-000AN5-AG for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 13 Jul 2023 17:50:39 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qJyZq-0004CX-65; Thu, 13 Jul 2023 11:49:58 -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 1qJyZp-0004Be-6J for help-gnu-emacs@gnu.org; Thu, 13 Jul 2023 11:49:57 -0400 Original-Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJyZn-000247-MU for help-gnu-emacs@gnu.org; Thu, 13 Jul 2023 11:49:56 -0400 Original-Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-99364ae9596so127130666b.1 for ; Thu, 13 Jul 2023 08:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689263394; x=1691855394; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=pnNrrVQg4X7v2BWQDdiBWWtqpz2w9E/+GhtjFO5r654=; b=QRJdoZYgvVScVB/VViSUq4uQxY6ZE+aTfWJFhM7mphQD7b/71zZaYhIKzj+mSBXpDM t+5G6nNQhHEfAb3kpxAyrm+W1pO8CS36dzcJ+qNegJZ6nQ/8XvnNyLbcTh/y5GkzeSKS fxdT12G3amVlZapUlZm55+8lvw7ezLUn9+avR6r8ec+e9swFFtMl8TfsaaYb1I0Etz+c I7+zV5VfTfJ08GDD6qroE4BVtkFT87JOSp6pbHA/VvJSZx3zDHZigS0ihuxqWxzFT+oX QtZFT6u4PGttmikZAxFIqzpzYWGaai9+Q7EcB5my2wIqoCvFEg4kTCNcAz7f5qVvgeZT A2BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689263394; x=1691855394; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pnNrrVQg4X7v2BWQDdiBWWtqpz2w9E/+GhtjFO5r654=; b=hgwvHOPhKmXlgwfD6hGCJrtNsvP4WIMg5w7x+VkCHujtTqzdAKgF3VN0jq5xvMDO1d 83ZknobHSKMyzMU1UsZFwn0SFlNHQZ5kdx28K+wRc+u/peGorSvMDMBUujCW+NUuSxFa aK9cd8blacJuGCDfu9/NsnkdTdmbEaUCTE7Dx3kroPD0AoR/AIVb+SRRIGWs/CwFOmo2 JAfrhc50svWNnpW0EkookTdufU5c0ZHXAkQn2fWBdszDGGauykJR/XICiO4J0EXILaJJ n3f2r/NZIMBu6VUrAHZCZMR+Y8KoLsGq/dvsXcK00V0fOjCylw+yrHUIUZPGJPN5xdvV +BCA== X-Gm-Message-State: ABy/qLb7QDZx4Pts0O2UErY2l1C+08x4tTlzR/Ju4+7mf6Wdf6Va4sbY fp6hSzsx4AxuDm5G1IM7CQ8= X-Google-Smtp-Source: APBJJlEHrquIjIY7GXt6qPHjgNtGey50Sb7BX7C8w3DkAzHfPeYOxADdxTjjieBGOcnbevkOuEb3PA== X-Received: by 2002:a17:906:5e51:b0:973:ca9c:3e43 with SMTP id b17-20020a1709065e5100b00973ca9c3e43mr1644482eju.45.1689263393836; Thu, 13 Jul 2023 08:49:53 -0700 (PDT) Original-Received: from [192.168.0.103] ([45.11.42.236]) by smtp.gmail.com with ESMTPSA id bl22-20020a170906c25600b00988be3c1d87sm4151659ejb.116.2023.07.13.08.49.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jul 2023 08:49:53 -0700 (PDT) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=platon7pronko@gmail.com; helo=mail-ej1-x632.google.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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, NICE_REPLY_A=-0.096, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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:144266 Archived-At: On 2023-07-13 18:40, Drew Adams wrote: >>> Every list is an alist. >> >> Can you elaborate? '(1 2 3) is a list, but I don't think it's an >> association list (at least according to Emacs manual - alist is supposed >> to be a list of cons cells, which '(1 2 3) definitely isn't). > > Well, yes; and no. > > "In Emacs Lisp, it is _not_ an error if an element of an association list is not a cons cell. The alist search functions simply ignore such elements. Many other versions of Lisp signal errors in such cases." (elisp) `Association Lists' > > (let ((x 5)) > (assoc-default x '(1 2 3 4 5) nil x)) ; => 5 > > None of those list elements is a cons. > > (assq 5 '(nil (5 . foo))) ; => (5 . foo) > > Element nil is not a cons. > > ___ > > The point is: specify what you really want when > asking to test whether a list is an alist. > > Even asking whether a Lisp object is a list is > imprecise - proper/true list or just a nil or > cons? > > Knowing what you're asking and what you really > want to ask is the first step (sometimes it's > even sufficient) toward getting the answer you > need. > ___ > > And be aware that if you test every element of a > list then that can be costly. It might in some > cases be better to just test as you go, _while_ > you're trying to do something with the alist - > e.g., while you're looking for an alist element > match. > > In many (most?) cases you don't really care > whether each element of the list is a cons - you > just want to retrieve the first match, and you > only want to traverse then entire list if you > have to (i.e., when there's no match or the last > element matches), and you don't want to traverse > it more than once. My apologies for not reading the manual thoroughly enough. Thanks for the explanation! -- Best regards, Platon Pronko PGP 2A62D77A7A2CB94E