From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Przemys=C5=82aw_Kryger?= Newsgroups: gmane.emacs.devel Subject: Should copy-tree assume bool vectors are vectors? Date: Sat, 30 Sep 2023 14:32:56 +0100 Message-ID: <5A6E2AF9-450A-4051-B4ED-972213855101@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) 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="15058"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Sep 30 15:34:22 2023 Return-path: Envelope-to: ged-emacs-devel@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 1qma6v-0003Zi-N4 for ged-emacs-devel@m.gmane-mx.org; Sat, 30 Sep 2023 15:34:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qma61-00014o-OM; Sat, 30 Sep 2023 09:33:25 -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 1qma5t-0000py-Eo for emacs-devel@gnu.org; Sat, 30 Sep 2023 09:33:17 -0400 Original-Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qma5r-0001Ie-Rk for emacs-devel@gnu.org; Sat, 30 Sep 2023 09:33:17 -0400 Original-Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-406650da82bso5755605e9.3 for ; Sat, 30 Sep 2023 06:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696080789; x=1696685589; darn=gnu.org; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=zIFO5/HrHDXjFxhZBpZjjlYV5HBmjOcw5ozCFgY7qUQ=; b=E8mEyiqKAf1J126LATuJlJHE/k9u1Uwt/4xsLSE6tx3pLUC0kMJrR96UgPYpwDg4Wl xkjaEuQz0k4LOf4h2Z8OQv+BKEn67gv1bf/5o8a2sK9PyWtBkL1Qp0xHyfDABJYwQ+sp 3/e3EJu4iDp5Nt5D8lpwI0iov4SvqrBlfAI+GKIiaoeGms0dml//YTApcSPOzmCIsRRG gfRz9gqfZKHEysz0sMCc0eqH3P7faK9QE+hoyzulpWmZ4pUVSxH11SpU+hIZo6C1QdKO fBk8vSjpVOmoIfAFvY8HNXI9y0M9E3R3+yRGFYQ/ELat00KKUQ2uJu5qbuD7bMGHnOVF hJxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696080789; x=1696685589; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zIFO5/HrHDXjFxhZBpZjjlYV5HBmjOcw5ozCFgY7qUQ=; b=oyxW+qaiPb93APy09PYUAHb9fSKXeWSKSEzjO7pcUxMWO/jRiiPF7bD27Pg3RazEW2 Q33k2rX4mplt4WFyLE8yWfBS3da4e0UnXUf2ZeeYHo3hY4ZjjWB/2tju7dPd4imsYtlK Voky0jX7FUVHXOa6ZlxkfkKT1tJPq6Nz8x+2XwsQW+xdjhjmFIUf89LLjSmYCTU1EUTq sp0s8L9woirsVxsFD1Sb4RVFCG5e6TN9MmQMB0m67ADh0yjaB8z2zO6RJHJ5egllMplK Oz1nOiq6+KVrjVZ4Pn0Oo7jRvimkYDTcLe2VW/7pj6dAzuwM9sFWENeW60ZOZ80Hseew 3wAQ== X-Gm-Message-State: AOJu0Yz+BXrYiaBwRoC6o9WCabGcLd9eoM1hMBG+kvhbhPZfi0oEmKbB FrWhbLErViNPkY8mVbP+IrLM2rBWg2k= X-Google-Smtp-Source: AGHT+IFflgc3/nmXI/roiThjddJRdOvBCtyxmrFPphmPDq35pRX/mfpijzECNe33hEO6gUIh/6z1EQ== X-Received: by 2002:adf:f888:0:b0:321:6953:6ae4 with SMTP id u8-20020adff888000000b0032169536ae4mr5779750wrp.37.1696080789079; Sat, 30 Sep 2023 06:33:09 -0700 (PDT) Original-Received: from smtpclient.apple ([2a00:23c4:f513:d201:b534:9a07:512e:390e]) by smtp.gmail.com with ESMTPSA id r8-20020a5d4e48000000b00315af025098sm23495657wrt.46.2023.09.30.06.33.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Sep 2023 06:33:07 -0700 (PDT) X-Mailer: Apple Mail (2.3774.100.2.1.4) Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=pkryger@gmail.com; helo=mail-wm1-x332.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-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:311206 Archived-At: Hello, Recently I=E2=80=99ve stumbled on a somewhat surprising behaviour of = `copy-tree=E2=80=99 function. Well it was surprising to me at least. The behaviour is that = bool vectors are not copied when VECP argument of `copy-tree=E2=80=99 is = non-nil. For example, my expectation was the following code to not assert: (let* ((vec (make-vector 1 nil)) (bvec (make-bool-vector 1 nil)) (tree (cons vec bvec)) (copy (copy-tree tree t))) (cl-assert (equal tree copy)) (aset vec 0 t) (aset bvec 0 t) (cl-assert (not (equal tree copy))) (cl-assert (equal (car tree) vec)) (cl-assert (not (equal (car copy) vec))) (cl-assert (equal (cdr tree) bvec)) (cl-assert (not (equal (cdr copy) bvec)))) I made that assumption after reading the documentation of `copy-tree=E2=80= =99: > [=E2=80=A6] With second argument VECP, this copies vectors as well as = conses. and info node of `copy-tree=E2=80=99: 5.4 Building Cons Cells and Lists > [=E2=80=A6] However, if VECP is non-=E2=80=98nil=E2=80=99, it copies = vectors too (and operates recursively on their elements). and info node: 6.7 Bool-vectors: > A bool-vector is much like a vector, except that it stores only the = values =E2=80=98t=E2=80=99 and =E2=80=98nil=E2=80=99. My understanding is that the existing behaviour stems from the fact that `vectorp=E2=80=99, that `copy-tree=E2=80=99 uses, yields nil for bool = vectors.=20 I can see at least the following options, but perhaps even better = solution can be found: 1. Do nothing. After all bool vectors are not vectors - `vectorp=E2=80=99 = clearly returns nil, and there is a separate function `bool-vector-p` for the = latter. 2. Update documentation to explicitly point out above discrepancy, = including some (all?) aforementioned places and perhaps `vectorp=E2=80=99 and any = other relevant places. 3. Update the code of `copy-tree=E2=80=99 to support copying bool = vectors when VECP is non-nil. I=E2=80=99m happy to contribute patches, should a need arise to modify = anything. Cheers, PK