From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#62068: 29.0.60; map-elt and map-insert for nested structures Date: Fri, 10 Mar 2023 08:09:29 +0100 Message-ID: <87ilf99j6e.fsf@gmail.com> References: <875ybafig1.fsf@gmail.com> <87zg8lh09g.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="342"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: "Basil L. Contovounesios" , 62068@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Mar 10 08:10:21 2023 Return-path: Envelope-to: geb-bug-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 1paWtR-000AXy-L0 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 10 Mar 2023 08:10:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1paWtB-00020Z-Ge; Fri, 10 Mar 2023 02:10:05 -0500 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 1paWt8-00020N-7t for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 02:10:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paWt7-0000eJ-VO for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 02:10:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1paWt7-0005Sg-JL for bug-gnu-emacs@gnu.org; Fri, 10 Mar 2023 02:10:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 Mar 2023 07:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62068 X-GNU-PR-Package: emacs Original-Received: via spool by 62068-submit@debbugs.gnu.org id=B62068.167843218020960 (code B ref 62068); Fri, 10 Mar 2023 07:10:01 +0000 Original-Received: (at 62068) by debbugs.gnu.org; 10 Mar 2023 07:09:40 +0000 Original-Received: from localhost ([127.0.0.1]:53527 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paWsm-0005S0-9F for submit@debbugs.gnu.org; Fri, 10 Mar 2023 02:09:40 -0500 Original-Received: from mail-ed1-f52.google.com ([209.85.208.52]:47069) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paWsj-0005Rm-Ni for 62068@debbugs.gnu.org; Fri, 10 Mar 2023 02:09:38 -0500 Original-Received: by mail-ed1-f52.google.com with SMTP id k10so16527227edk.13 for <62068@debbugs.gnu.org>; Thu, 09 Mar 2023 23:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678432172; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=JU50sPfBBCaBGAXVrs7Df7GCdyliF6bT/P4K7nncmsI=; b=WBoyaabExtWAiksViLNzbmxOW/DcWfFW185+66HV2voGp8pLWVYIxWEEuNKUoDxOJu DsXuKNTMCFMBvryeFsdpbeSaNfRvzMqkuU/fTypkZs6nftRG/LQ5MVra4zA6ecGW/UVZ 5Fuy5gLyj9k0Eb/kNoYHpbDRZQlUnxshpwQyYcZMSBCd03fuPP+3WsDizLyMKDCwhUoV 0xCl6Juxy4f9vj83ED6dG6OFKRerZNh2VjZo488LQ6z6qyD/uv+Qc2AkMNnVG9rcQ8+t WHe4hsFsjlS/AT1LC3I0xGWMhv6E2Zo3d/MQ6QaiWw/OC9vnvyB1FWBhEX+A/DgX7oeV qpVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678432172; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=JU50sPfBBCaBGAXVrs7Df7GCdyliF6bT/P4K7nncmsI=; b=a/9pV+sTJHi79HZwDLVLaOEnACLZF6SBesM3z6svIIykOXL+arbc3wz0hGw6rjmH8p v5WGo0aElxT3U+FzeMBZ4CToPv8SMWxEQLhtOXI+VwSTGSMAQLKS7HSW0oL5788uxjsW C57nN/hWrmI9jgTzzPimmoG9yAaIgQDJQ8K5WSPDyKlgKstr6XXr+PlEbRb4VuAlj8KX B/XNhKSBpLShnRyo3TtTAdiY1kmI1ucX4Q0LMInqxTmHSXcQwLOHy3SrB4WjkxvufRMk Kqo2dXlIk3274jp237zTK/CMYpj3kdUcHCUXro06nnoHdfDxRVeZln1E4wCQ8Zb2mqzI QVVg== X-Gm-Message-State: AO0yUKXRnIgL1toBnEH2IGTzhrG1Jcp+v0vvhuQamLPyGTI4S1C/BJGI FrAXjn5IUKVN3vUSqjj+XJs= X-Google-Smtp-Source: AK7set/gpF1g63xZWDk41rQ8ID+riSrg5G5EmySRfoWIkRE7Ex6sDapq9cEequvqRFb0K7mZ2qvbZA== X-Received: by 2002:a17:906:1c13:b0:86c:a3ed:1442 with SMTP id k19-20020a1709061c1300b0086ca3ed1442mr22848531ejg.4.1678432171594; Thu, 09 Mar 2023 23:09:31 -0800 (PST) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::8b3a]) by smtp.gmail.com with ESMTPSA id m20-20020a1709060d9400b008c607dd7cefsm580566eji.79.2023.03.09.23.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 23:09:31 -0800 (PST) In-Reply-To: <87zg8lh09g.fsf@web.de> (Michael Heerdegen's message of "Fri, 10 Mar 2023 02:18:35 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:257651 Archived-At: On Fri, 10 Mar 2023 at 02:18, Michael Heerdegen wrote: > Augusto Stoffel writes: > >> I would like to suggest the following two functions to deal with nested >> maps. Let me know if you would like to see a patch. >> >> (defun map-elt-in (map keys &optional default) >> "Look up a nested sequence of KEYS in MAP and return its associated value. >> KEYS is any sequence type supported by `seq'. If a key is not >> found in any intermediate step, return DEFAULT, which defaults to >> nil." >> (catch 'map--break >> (seq-reduce (lambda (m k) >> (let ((v (map-elt m k 'map--default))) >> (if (eq v 'map--default) >> (throw 'map--break default) >> v))) >> keys >> map))) > > Isn't this more or less the same as `map-nested-elt'? How did I miss that? In any case the more interesting bit is the other function, which should then be renamed to `map-nested-insert'. Now, `map-nested-elt' has an inconsistency regarding the DEFAULT argument which needs to be fixed. (map-nested-elt '(a nil) '(a) 1) 1 (map-nested-elt '((a . nil)) '(a) 1) 1 etc. While in the other hand: (map-elt '(a nil) 'a 1) nil (map-elt '((a . nil)) 'a 1) nil etc. Also inconsistent with the rest of Emacs: (let ((m (make-hash-table))) (puthash 'a nil m) (gethash 'a m 1)) nil (alist-get 'a '((a . nil)) 1) nil