From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 09 03:16:44 2023 Received: (at submit) by debbugs.gnu.org; 9 Mar 2023 08:16:44 +0000 Received: from localhost ([127.0.0.1]:50834 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paBS7-0004o5-Ld for submit@debbugs.gnu.org; Thu, 09 Mar 2023 03:16:44 -0500 Received: from lists.gnu.org ([209.51.188.17]:37080) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paBS5-0004nv-Sg for submit@debbugs.gnu.org; Thu, 09 Mar 2023 03:16:42 -0500 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 1paBS5-0002si-GY for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2023 03:16:41 -0500 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1paBRy-0008DB-Vv for bug-gnu-emacs@gnu.org; Thu, 09 Mar 2023 03:16:36 -0500 Received: by mail-ed1-x536.google.com with SMTP id i34so3692302eda.7 for ; Thu, 09 Mar 2023 00:16:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678349792; h=mime-version:user-agent:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to; bh=aRitDrsyUtCym2Psp9yyHod0c8oUhrgpseWMLQnYZSE=; b=OOkhRWSueX+RTubJhAeTzOcpEBGXlLJ31G7sP3kiH34R3Lpdrgs8rHlDlEyj2YYe+M LDDPBPBJUx7qgt/TpG+0Oy7xAFE9860OCrFnqmcsgZ084B8Nu8MH2wFJ9ZZy4fbBKsu6 /x7YfsoF4VmPFmGnoP9im+lBsZ0z/oV7Lk7FwmehcyRCX0B5bpUtPBI3F43j3rV2rxLc fWZRhu0VLNsQjHZIuhZZp8dM8jI/lOWrAQyPWBlERMSV6mDQNzCyR7CX4lSYyWruOTvK k/ZMu7+06/MvRZyFhgBZcd+x+7WCeb+2K9PDq8+QIy9O5yb2UaDwRQNNXYrULSg4eKuV 0W7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678349792; h=mime-version:user-agent:message-id:date:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aRitDrsyUtCym2Psp9yyHod0c8oUhrgpseWMLQnYZSE=; b=S/VIEpONjfee4DjWAb4qKWKtfpWeNv7F5KbHGIvvkM1n9Bcu7S9tb7HTP1iVH6rdlg e7dkWjNZW2Hh2amPjp+htrGhdJMfHrS1/7gRmFeQpuP4ucXAVF+LyuIompurR/5ixIhy vi9ERNkOtUgf1pgxUiN3C1gLE1+DyN/FtN+DhKPgYUZrGld/Egku7hQURcJR1mm3Rz/w Tf563jZaGaoEAKa5QlW9WkDlImw2AAx4U4MJEykO24uW92XdgaK4iv9JA2c8HGN1BKmy k/9TTXnpuiIvJIWWxyyz9lzc9xvg4waiKDiQpWW4JrpOqJmPWQRrpN11soPgPINyDOf+ iFlg== X-Gm-Message-State: AO0yUKUnBAI2QxunVOjSWqPhpaD4Co54jjVaSz554c6CTmo6ml41ZdWC l59nKpCc1bv7bCGN7YJMLrbbbHfQhHYmzA== X-Google-Smtp-Source: AK7set80NrQPuXAQw31fsBgeN7XwJ5AGNzfPBkJ8OkXlXXX9EKR+EATzRnAn/Bf1vE+ooKNWzT2sQw== X-Received: by 2002:a17:906:b050:b0:8b1:e791:faef with SMTP id bj16-20020a170906b05000b008b1e791faefmr20313873ejb.67.1678349792075; Thu, 09 Mar 2023 00:16:32 -0800 (PST) Received: from ars3 ([2a02:8109:8ac0:56d0::8b3a]) by smtp.gmail.com with ESMTPSA id n6-20020a50cc46000000b004bcee7838c8sm9156444edi.75.2023.03.09.00.16.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 00:16:31 -0800 (PST) From: Augusto Stoffel To: bug-gnu-emacs@gnu.org Subject: 29.0.60; map-elt and map-insert for nested structures X-Debbugs-Cc: "Basil L. Contovounesios" Date: Thu, 09 Mar 2023 09:16:30 +0100 Message-ID: <875ybafig1.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=arstoffel@gmail.com; helo=mail-ed1-x536.google.com 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_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 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. --8<---------------cut here---------------start------------->8--- (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))) --8<---------------cut here---------------end--------------->8--- Examples: (map-elt-in '(x (y (z 1))) '(x y)) => (z 1) (map-elt-in '(x (y (z 1))) '(x y z)) => 1 (map-elt-in '(x (y (z 1))) '(x y zz)) => nil (map-elt-in '(x (y (z 1))) '(x yy zz) 99) => 99 --8<---------------cut here---------------start------------->8--- (defun map-insert-in (map keys value &optional default-type) "Return a new map like MAP except that it the nested KEYS with VALUE. This does not modify MAP. KEYS is any sequence type supported by `seq'. If intermediate values are missing, they are created with DEFAULT-TYPE." (when (seq-empty-p keys) (error "Keys sequence must not be empty.")) (named-let recur ((map map) (keys keys)) (let* ((k (seq-first keys)) (ks (seq-rest keys)) (new (if (seq-empty-p ks) (map-insert map k value) (map-insert map k (recur (map-elt map k) ks))))) (if (and (not map) default-type) (map-into new default-type) new)))) --8<---------------cut here---------------end--------------->8--- Examples: (map-insert-in nil '(x y z) 1) => ((x (y (z . 1)))) (map-insert-in nil '(x y z) 1 'plist) => (x (y (z 1))) (map-insert-in '(x 2 y (z 3)) '(y a b) 1 'plist) => (y (a (b 1) z 3) x 2 y (z 3)) ;; Looks funny, but see bug#62067 From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 09 20:18:51 2023 Received: (at 62068) by debbugs.gnu.org; 10 Mar 2023 01:18:51 +0000 Received: from localhost ([127.0.0.1]:53353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paRPG-0003dX-VM for submit@debbugs.gnu.org; Thu, 09 Mar 2023 20:18:51 -0500 Received: from mout.web.de ([217.72.192.78]:60043) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1paRPE-0003dG-N8 for 62068@debbugs.gnu.org; Thu, 09 Mar 2023 20:18:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1678411118; i=michael_heerdegen@web.de; bh=F9ReQrQeh6c/1i+BPDRoNmPBBT43giRDYIuF2J4WvY8=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=D2ZRO1xnAN7Wrf8pCCts55LnY5fN5wAfzSfX44IQxb7WMPJ9pAknSURSZq9wHp156 HVjEqNYcZi37N02CvgLjCsSjC9pVqR8BlQHTVM1DE9DA3woZY+VH6+cV49p3KBmxB1 O5zGOkdqzTkClFdQKoyCduuY269Te+IIBL0+XOrcIw4uCtVNnjgPqLraYJrr3XCsJE jnrT4UMxeoLv9wezb4mTJ9W/6kqJ2BhtYSFxhwOMeHLDnfpmGZIPU1EYt5JdF5e2YS v1H90Ly0gdyV01Z/sFF4lkwmLRALbUDtDaBBQJw0bjAihct1DdT6cS1TZBv6lp2Qcs N4fLKpIz9Tn0w== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from drachen.dragon ([178.14.74.115]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MXXN7-1q3zP719tH-00YlF6; Fri, 10 Mar 2023 02:18:38 +0100 From: Michael Heerdegen To: Augusto Stoffel Subject: Re: bug#62068: 29.0.60; map-elt and map-insert for nested structures In-Reply-To: <875ybafig1.fsf@gmail.com> (Augusto Stoffel's message of "Thu, 09 Mar 2023 09:16:30 +0100") References: <875ybafig1.fsf@gmail.com> Date: Fri, 10 Mar 2023 02:18:35 +0100 Message-ID: <87zg8lh09g.fsf@web.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:GRyV0rWe3JDCuj8C4qQeEQ94Mexok9avFlm9jpDiTfCcOeFLdK0 hGcqSh1mnsB9HX/tV4f3NxeEC/FixiS1MbxDEAWiJ0Wd1xAhE3kCSdInemjJmqDufxINDB7 tWDshivTGouFrxaFlKWEosMCeXpl96Lbk8etOKU3EKboFAKQoYpxhoMBpC+duo4AbOJgwhv 7vE0L/7lfKP0PZ8bjmCow== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:NmmBZUSLqW0=;4XKUjPvsgJb+Z4sI1XnxBN+kkjB 2OoyHYO9yFFiFexxa3FW5xyAeayZG5AIzKwyPdiBoWEmCE8d1J3mMBpdZL+tLX4hKY03bRx5n VO02xnr+AyxU0QdZdTVtOc0AT2DevJxt6Po97fH1uK6IHgp72RnzMq3oLTfQnX3rpgb4GTEyA mV+nfo0f0pk2KGqc8KVfPDzUwWIzD8Yl5zYPfnpb/DEYYi83lQ1dVOPElfSfAUIjVMZns5rBx yapyYl+Rc2X65XE7VJro4vtDfxRyTeSDldjvzJyaW9sxq2Tmguhe69GZNEYjYgEUqCDAxBR89 z1P7UMggo19LD13fTiZRpEqzqnMsVuJ3LO0GZq4BCkqv1WGByPWnFtffQqnO/iBCCngKNkmBz EjsqjgTTLt1vfdUfoK/2fLAFpNmjkLcfh27vPE/NY87OXUPjsgnxXdE/d/pmiVLqxbFyAT3eP nKMs+TZzslMnR+4jHEh5wGd7C20tAe6nol2yD1ux1PQurh+4uE2dUnHNil3nlB31+TQmjqM65 /2Y6KTvZHvKXgg/yatqu0OPd+FeAKm27S+5pxgWTSrIJW2vnQgXSkVwUna3j428nEPZQz+v3K 7mmZnmRN+C5K22RWdEOMk02EpGo4twOUb5x9XONz5IcaDoOQ3tzx2pL08JkDC3aphDqFXE/1t mMgBe7nhsKhtASlvAXVoRPWcBRcXryBzCg6f0v+UblX9MzRczaTUn/rbRTvfHGEq+V+Eq20U+ Jfhaw88HaYVq2Lkgf2KejrTLSuVBPFvmKFCcBQKwhcNMpugLAIb5zNVKf1X4HEMIA3lD+z1t5 tGNmaPaH9IJGMzH/cNmF41SLItRj1ptvAsKUbJZEPTvH27YDRyMQxabsIbDRzbACJ9QGOk6F+ Dz7WqXq2jxmmOlvx32nItck5CSDLfncuanvERr4AehQQ2b0060zx6QPu7RlInnxwzvDPrvOkp ycHpfQ== X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 62068 Cc: "Basil L. Contovounesios" , 62068@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) 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'? Michael. From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 10 02:09:40 2023 Received: (at 62068) by debbugs.gnu.org; 10 Mar 2023 07:09:40 +0000 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 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 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) 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) From: Augusto Stoffel To: Michael Heerdegen Subject: Re: bug#62068: 29.0.60; map-elt and map-insert for nested structures In-Reply-To: <87zg8lh09g.fsf@web.de> (Michael Heerdegen's message of "Fri, 10 Mar 2023 02:18:35 +0100") References: <875ybafig1.fsf@gmail.com> <87zg8lh09g.fsf@web.de> Date: Fri, 10 Mar 2023 08:09:29 +0100 Message-ID: <87ilf99j6e.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 62068 Cc: "Basil L. Contovounesios" , 62068@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) 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 From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 10 22:22:29 2023 Received: (at 62068) by debbugs.gnu.org; 11 Mar 2023 03:22:29 +0000 Received: from localhost ([127.0.0.1]:56341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1papoS-0006I6-Oq for submit@debbugs.gnu.org; Fri, 10 Mar 2023 22:22:28 -0500 Received: from mout.web.de ([212.227.15.4]:59067) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1papoQ-0006Hs-S8 for 62068@debbugs.gnu.org; Fri, 10 Mar 2023 22:22:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1678504937; i=michael_heerdegen@web.de; bh=VsmEDJINZMg9xVAcaiJSV4z0giD7QoOW/r5/TlYw5Wk=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=gFMsBW/fc7v18JfJuCcRrp05PrZ9g6yiI8635VXmQOGUQc9+NBCHLhpEo3vzWXcxY QsICHs0TRaP5WSqUCVfzR/gbNzvUdXgzfcGCHz4gY9xvMQMlvV9OTxh9YprdcDqqic nxcaplYwL0qyXS8nGb3b9fnjZYhgvDS1rlYhvsYidOtUpYvAV8pVxzZSL8m50pof95 sXVPYYT55N+hFYTCsQtluNRiFVTYUXNTCVCurU2CTmXAMlaUFA3qahujKX34+Cg1CX WVv405NPGkwdQSyoyegkpzdf1UTP2f74/uNI2VOnn7vPLehtZtDIkibcxutMh7BkN4 yy8FisQDF4ZSQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from drachen.dragon ([178.14.74.115]) by smtp.web.de (mrweb006 [213.165.67.108]) with ESMTPSA (Nemesis) id 1MMXx5-1psdmJ3YWN-00JI0Y; Sat, 11 Mar 2023 04:22:16 +0100 From: Michael Heerdegen To: Augusto Stoffel Subject: Re: bug#62068: 29.0.60; map-elt and map-insert for nested structures In-Reply-To: <87ilf99j6e.fsf@gmail.com> (Augusto Stoffel's message of "Fri, 10 Mar 2023 08:09:29 +0100") References: <875ybafig1.fsf@gmail.com> <87zg8lh09g.fsf@web.de> <87ilf99j6e.fsf@gmail.com> Date: Sat, 11 Mar 2023 04:22:15 +0100 Message-ID: <87r0twt1js.fsf@web.de> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Provags-ID: V03:K1:gmIIr/dRfSzZm2tNF3zaJwAEwke3BRN/YFGbUc2uhxSMa9vcMfI 7SkmGdZ9kU6fMEcm0ZrMheCUBs9Z0qsxxHLDTGiEFNVJDaiTkL8FKIpOPt90b9TAohP1JQB ATzV58jdW1cZMxZ3Yr4yDndD9SXdMzM7KdPrTy+NJxN29DRlH4Iey/8MFJAXvUeA/16J2kQ cqL9gbJnYCqK0S/Ymyg/g== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:CLG2G2UxAY0=;i2opWDjgYs1562YC79nCtPikIMp JKeEpC+TGMwN+mo6H/AEvL8+hwW38WSXsLurH3Tv78/ZB/vuqXw/bWgb2M8tAeqKWF46xLKJH lkcIx9MkUnZtnZyfjKboxzrHMa3v4YVGwCo/KTPsQku1Guq/ERV/IL5KIL4lOP5P7vqjcKl0v zRObw9xSZW/viJ0BwW4rOsgvkC1pX3Z7NaOSYlx2UojZAlxy1SSEBwCNOJ4WfnlAwqjlBQ6Ig M+ru0e65tm5FskUG1uXZYPeqvUGb02wbGikhMyRJMDS55B3JPr7s6lzlRukjHU0J1xtbXKBVd xFggmVeRpJsPAOumbjYYqpyltCMb/Mps21muonxDSG9apKrrq1PPqzryiSuSKhFP3gs718dTD NqzWEBwOaBldfmbFf8yB5Nk0kUlHXDGYrXtqW/c1WxDpFI+AtxcjxMot5MQ+tgYjDkl54b3bB 9PlvQOg6pSfwkQFAsX4PqjMIjK+RjDvyWp1pLXxfkcq4g/ssKHtz6KCk+TsApMdacZl5n3nkZ /tAYBnFipKMW8MiInqzlRTtV2RnZlUEpc6u7AjHLz+7KljhKq6/X2q8cFaX49AkSZ1OhP2fBN sxduSWz4oZaLuLZykLgK4SfBPddykXo1ttFAODvTULHmY6qXHE7+MWqDz0CgacMMeuFGG+Emx WC1gJEiJo0/0GZzqXhwlAy90UAtaxb3wX/qqoafUY/8MiSEN8w1azrfCCfKfrEbsC6c5BKz9J bjrKdMqQgcubNX1JRxYG8dbcOTWQVakzRVToKdMnfW55BTuYUdxYU2oiiy7ZRMlhJDI8GgP2V UJhpt3q1D5sZhhJR4aWrDmVq9v/k4HZ6CUMWWpwc13IwG1uLhBAQfJlPbYHOYHi/IwBYdzCYv 9tor6LwGvCAOgEC53AXxVIX70BSQaUwGerGyVFBdG+ixft/xBnM7LEFtquHI0zWbo9skWzDZC DXnlmrFim0OxkGX0PA/jv5g8D3U= X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 62068 Cc: "Basil L. Contovounesios" , Nicolas Petton , 62068@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Augusto Stoffel writes: > 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'. Is that something one will really need often (honest question, I'm really curious)? If yes, I wonder if we should make it work as a generalized variable. > 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. > [...] That's a good point indeed. However, `map-nested-elt' exists since the beginning of the library in 2015, so it could be that existing code relies on the behavior (maybe that's why you wanted to add a new function?). But it's a terrible inconsistency. CC'ing also Nicolas. Should we maybe just add Augusto's version and deprecate the existing function? Thanks, Michael. From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 11 02:51:43 2023 Received: (at 62068) by debbugs.gnu.org; 11 Mar 2023 07:51:43 +0000 Received: from localhost ([127.0.0.1]:56473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pau11-000526-4c for submit@debbugs.gnu.org; Sat, 11 Mar 2023 02:51:43 -0500 Received: from mail-ed1-f54.google.com ([209.85.208.54]:37734) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pau0y-00051q-Uh for 62068@debbugs.gnu.org; Sat, 11 Mar 2023 02:51:42 -0500 Received: by mail-ed1-f54.google.com with SMTP id j11so29598950edq.4 for <62068@debbugs.gnu.org>; Fri, 10 Mar 2023 23:51:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678521095; 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=RF7LSYL3R8OL6rKseLDFqcs5A/MFtECXTVLl8GZP89E=; b=V/bZ0ekg5466pNJXp5JVQgweLpB/p/MdNOkSbYlqI1sp8nzHyUHczSgH3dANLhz3LL 2lQB3oMUR7TVgTMARyaZN02ZU92wmi0/36Fwzv4FeAhyvW5BuH6jYxg0IyY638ICU3hb MZbbZc0Cmh0OjvNLDUdGd5DQHsvJpcnCHGMG2HLRVcuvZDpnjvDf4CSHsDN+myQJhetX 5BIbTobrMlIBFHkjrmIN+HoemVfktdyb/Nrc38SwfnEYDQ7AKsMKjhuuoGC7Iq1qZXvH DurNDQBb5RTcP0YqoLpI4QRgxpnppHTj63oRHfzU7evjAVO0A7VLwd2fm3uhXyPyn0iy LC9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678521095; 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=RF7LSYL3R8OL6rKseLDFqcs5A/MFtECXTVLl8GZP89E=; b=dW54Oz/eq9DPbXwLIjEzlR0xtm4tKXxz5c8pSipKrbIR48epq8PsfBfeRtQfsoN2Hb YtsAO9W0xKOVcHnURy1LTPFcSUt94gf0TwEiSRN+zA3KEhu2SfFcglKhcatNZmfsWe5X wCRsroWAWs8yCNCEJkdFCeeNPE3uwT+zc6jQgA8c8Qg0nMAPoWb6blWEkc1eFg/S44Kg NX+ISes4QfpHd/1HRXYzzPurQRzj2byV0CpWn4bq7/f2uZ/gIRc/WDdGrw8LfPMITRZ2 LYhNtMH8mOxX6rynImoSjIp9kcRdj1AuaBPR0x5V+wfbqBy2KEfu4cniaRDQCpijNEmC ay7Q== X-Gm-Message-State: AO0yUKWz0I8a31/5EJfyu4ayG9pMda+hxfS27vPdq4e8XpBbJK0Pma0c P6CskxZ0AGxC5rUC323Cp8o= X-Google-Smtp-Source: AK7set85bqxO0ds7uGjJ25Qz+BR41ofrLwpt4v54UVqP/XogwAZQ3n8ZiqaeeWxTYX+4AO1Ka/V2og== X-Received: by 2002:a05:6402:654:b0:49e:1f0e:e209 with SMTP id u20-20020a056402065400b0049e1f0ee209mr5241732edx.10.1678521094978; Fri, 10 Mar 2023 23:51:34 -0800 (PST) Received: from ars3 ([2a02:8109:8ac0:56d0::8b3a]) by smtp.gmail.com with ESMTPSA id d30-20020a50f69e000000b004bcee7838c8sm853471edn.75.2023.03.10.23.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 23:51:34 -0800 (PST) From: Augusto Stoffel To: Michael Heerdegen Subject: Re: bug#62068: 29.0.60; map-elt and map-insert for nested structures In-Reply-To: <87r0twt1js.fsf@web.de> (Michael Heerdegen's message of "Sat, 11 Mar 2023 04:22:15 +0100") References: <875ybafig1.fsf@gmail.com> <87zg8lh09g.fsf@web.de> <87ilf99j6e.fsf@gmail.com> <87r0twt1js.fsf@web.de> Date: Sat, 11 Mar 2023 08:51:33 +0100 Message-ID: <87356bvi7u.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 62068 Cc: "Basil L. Contovounesios" , Nicolas Petton , 62068@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Sat, 11 Mar 2023 at 04:22, Michael Heerdegen wrote: > Augusto Stoffel writes: > >> 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'. > > Is that something one will really need often (honest question, I'm > really curious)? I think it's very useful when you need it :-). Actually, I wouldn't use map-elt in any code, because I always know what type I'm dealing with. I would just turn to this library for special maneuvers that the basic API doesn't offer. > If yes, I wonder if we should make it work as a > generalized variable. Maybe, but that's a separate story. First and most importantly, in my opinion, the library should work right on values (as opposed to places). >> 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. >> [...] > > That's a good point indeed. However, `map-nested-elt' exists since the > beginning of the library in 2015, so it could be that existing code > relies on the behavior (maybe that's why you wanted to add a new > function?). (No, the reason was just pure oversight. Maybe "elt" is a weird word? Why isn't it `map-get' and `map-nested-get'?) > But it's a terrible inconsistency. There are more consistency issues in this library, see bug#62067 and bug#62117. Emacs has its quirks and one of the selling points of map.el is to be a more consistent layer on top of the basic APIs, so I'd say this need to be fixed.