From unknown Sat Jun 14 00:09:53 2025 X-Loop: help-debbugs@gnu.org Subject: bug#48318: (ice-9 match) does not allow distinguishing between () and #nil Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 09 May 2021 16:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48318 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 48318@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16205785835561 (code B ref -1); Sun, 09 May 2021 16:44:02 +0000 Received: (at submit) by debbugs.gnu.org; 9 May 2021 16:43:03 +0000 Received: from localhost ([127.0.0.1]:56202 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfmWF-0001Rd-Eg for submit@debbugs.gnu.org; Sun, 09 May 2021 12:43:03 -0400 Received: from lists.gnu.org ([209.51.188.17]:46270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lfmWD-0001RD-U7 for submit@debbugs.gnu.org; Sun, 09 May 2021 12:43:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfmWD-0008Gz-EU for bug-guile@gnu.org; Sun, 09 May 2021 12:43:01 -0400 Received: from baptiste.telenet-ops.be ([2a02:1800:120:4::f00:13]:57922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfmW7-0008Pt-J7 for bug-guile@gnu.org; Sun, 09 May 2021 12:43:01 -0400 Received: from butterfly.local ([213.251.116.230]) by baptiste.telenet-ops.be with bizsmtp id 2giq2500C4yL7Jl01girJw; Sun, 09 May 2021 18:42:51 +0200 Message-ID: <4c8839f49a6c7317324d5360d74594c181b0588b.camel@telenet.be> From: Maxime Devos Date: Sun, 09 May 2021 18:42:40 +0200 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-W7rR4/1OKaSnlkD/yGzq" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1620578571; bh=7wkOmWiEKsCwhuuaqm/p8KeOavnK7CDbREpqWJa2+Fg=; h=Subject:From:To:Date; b=aKnPqmtsi6b3142x8U/0faw2a7DVnuutM9wYiE/QrD/guKP4/6PV1WjqoSXBYaqkX ExusR48lTJGFJ+9k8V40/hLXHgJ4WwTELagAEMDXlokgWBYoB6KWGdtCL4Ju3hLp8Z Phnq2nsGPfmcV2B3JRknVQJN6ZuV5CLJjLSqEsPmma9S6DB5nGrjAHhwIFWpNen8bk vbPk5HZ7zCubIMcjM4wgWKhSe95xj7K6S8ihvAoa3YKDGkVaBLCt4yhsHI2AGbO7gA 3fJFPTM8zc3N0K7gudHUIbjiBceH0GWL/Unuvsq5JnR2J4QWL6NcYuSKpM9sGQZSAm AnRcwqj9kh6Jw== Received-SPF: pass client-ip=2a02:1800:120:4::f00:13; envelope-from=maximedevos@telenet.be; helo=baptiste.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -0.5 (/) 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 (--) --=-W7rR4/1OKaSnlkD/yGzq Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi guilers, I've found the following surprising behaviour: (use-modules (ice-9 match)) (match (identity #nil) (() 'scheme-eol) (#nil 'elisp-eol)) --> scheme-eol, expected elisp-eol (match '() (#nil 'elisp-eol) (() 'elisp-eol)) --> elisp-eol, expected scheme-eol Treating () and #nil as equivalent makes sense, but should be documented. My suspicion, currently untested: the following code in ice-9/match.upstream.scm ... (define-syntax match-two (syntax-rules (_ ___ ..1 *** quote quasiquote ? $ =3D and or not set! get= !) ((match-two v () g+s (sk ...) fk i) (if (null? v) (sk ... i) fk)) [..] should be: (define-syntax match-two (syntax-rules (_ ___ ..1 *** quote quasiquote ? $ =3D and or not set! get= !) ((match-two v () g+s (sk ...) fk i) (if (eq? v '()) (sk ... i) fk)) ((match-two v #nil g+s (sk ...) fk i) (if (eq? v #nil) (sk ... i) fk)) [...] And the following might need similar adjustment: ((match-two v (p) g+s sk fk i) (if (and (pair? v) (null? (cdr v))) (let ((w (car v))) (match-one w p ((car v) (set-car! v)) sk fk i)) fk)) Greetings, Maxime. --=-W7rR4/1OKaSnlkD/yGzq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYJgRABccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7sMsAP46Jl7Xfo8PL/lkADk9yc7MvtVr whcPMIpVkvgLIauCKQEA113noQSu2c4N38v3QjG3BmN8+KX1qsAZwBEpOyyN2gE= =8eS9 -----END PGP SIGNATURE----- --=-W7rR4/1OKaSnlkD/yGzq-- From unknown Sat Jun 14 00:09:53 2025 X-Loop: help-debbugs@gnu.org Subject: bug#48318: (ice-9 match) does not allow distinguishing between () and #nil References: <4c8839f49a6c7317324d5360d74594c181b0588b.camel@telenet.be> In-Reply-To: <4c8839f49a6c7317324d5360d74594c181b0588b.camel@telenet.be> Resent-From: Taylan Kammer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 13 May 2021 19:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48318 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 48318@debbugs.gnu.org Cc: Maxime Devos Received: via spool by 48318-submit@debbugs.gnu.org id=B48318.162093327413540 (code B ref 48318); Thu, 13 May 2021 19:15:02 +0000 Received: (at 48318) by debbugs.gnu.org; 13 May 2021 19:14:34 +0000 Received: from localhost ([127.0.0.1]:44332 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhGn4-0003WK-Ju for submit@debbugs.gnu.org; Thu, 13 May 2021 15:14:34 -0400 Received: from mail-ed1-f48.google.com ([209.85.208.48]:39487) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhGn3-0003W7-7s for 48318@debbugs.gnu.org; Thu, 13 May 2021 15:14:33 -0400 Received: by mail-ed1-f48.google.com with SMTP id g14so32188329edy.6 for <48318@debbugs.gnu.org>; Thu, 13 May 2021 12:14:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=wFXcbr3gjKeMsg21ZxoQG7ULMj6t7lbnmNJtfUqk5R8=; b=H7fxJX1tHZinJ+JrmHuDv+pTPhlY+qOcL4kZq36Q3gk8uy8M4A3LskwZneTcjIVleS G0CyQwi+XPwm0tSF+a+csQur1jIpwW/yiQtP23Qrhs3tb+2CZiTHjiE0/hDwDjwC0uPI Wi0b2QkeDtPUHUIafO4UtfgzYwlvkwvnVwYqjhhepbI9Ikhg57sK39FZeu666zx674rl snEmTE9expo6DvrjZDVup5AfVp2VxdJlLAPljw78hAhnAs98G0y2OPsdMkQfHxL80EzL Fm+BMcjTQ6JHYsK1zUVq1uLquHP7I2UJpBEaQ+zqbwdViCkYUlNjMUAaooIAAcbjQ5JM QyPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=wFXcbr3gjKeMsg21ZxoQG7ULMj6t7lbnmNJtfUqk5R8=; b=tvp+0ZIlOtRavK8RU93mXZDNz19pmZ5F/b79JixwWJ3weTnpmA04fivs30PHHezfFr bEZj2zZsdi6vZKfdV2sc4zpbn7/P2x3lKFfMJ/76a5dldw/fyrtIvHVJheufrrhhu44x 3v4oQv4zDaIKyST9sKCWprj9XSsJnp/N3PBLoXrpDdIGNrGWAlrJRKZcjOsWAyZIpFyY IPKA7t9b+qpLO9XLCxKE+S95a0wqhe1qPrHx6Hro8im+j7tJHUuNb4mKcHawRBGxRl9z /Sor5Z2ZczBYHW2I0silUmLpDI/MVPSYppwK7s0kNVCjbIkHYiw2/zOT9gdQycOkRHes 3H7A== X-Gm-Message-State: AOAM531G5r9twMxrklbs1ly0Zv537TFnv2bnoqEDq/kXihUhjBlryjeM HT5L/GaeZOGuiCnp8HJpRKI= X-Google-Smtp-Source: ABdhPJxJpSzQd66uEX7U7rN5e2KRpfiYdOMssvsbMs8oKLEQxID000VgzxmhyvIM/Hou/U7Rj3LKpg== X-Received: by 2002:aa7:dad1:: with SMTP id x17mr51898698eds.47.1620933267490; Thu, 13 May 2021 12:14:27 -0700 (PDT) Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id a22sm3001583edu.14.2021.05.13.12.14.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 12:14:27 -0700 (PDT) From: Taylan Kammer Message-ID: Date: Thu, 13 May 2021 21:14:26 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) 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 (-) Hi Maxime, I believe that match conflating () and #nil is the right thing, even if the current implementation does it unintentionally. Those two values should be considered "the same" in most situations even though (eqv? #nil '()) is false. In fact I think they should be equal? to each other. It feels wrong that (equal? '(foo . #nil) '(foo . ())) evaluates to false, even though both arguments represent the list '(foo). Please note that #nil is not ever supposed to be used intentionally. It's there purely as an Elisp compatibility trick, and the only time Scheme could should receive it is when receiving data generated by Elisp code. For instance when Elisp code generates a list, it would be terminated by #nil. (Which is why I think it should equal? '().) Does that make sense to you? I'm not sure what the Guile maintainers would say about (equal? #nil '()). - Taylan From unknown Sat Jun 14 00:09:53 2025 X-Loop: help-debbugs@gnu.org Subject: bug#48318: (ice-9 match) does not allow distinguishing between () and #nil Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 13 May 2021 20:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48318 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: Taylan Kammer , 48318@debbugs.gnu.org Received: via spool by 48318-submit@debbugs.gnu.org id=B48318.162093840721441 (code B ref 48318); Thu, 13 May 2021 20:41:02 +0000 Received: (at 48318) by debbugs.gnu.org; 13 May 2021 20:40:07 +0000 Received: from localhost ([127.0.0.1]:44389 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhI7r-0005Zg-6J for submit@debbugs.gnu.org; Thu, 13 May 2021 16:40:07 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:55732) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhI7o-0005ZM-B9 for 48318@debbugs.gnu.org; Thu, 13 May 2021 16:40:06 -0400 Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by laurent.telenet-ops.be with bizsmtp id 4Lg22500J0mfAB401Lg21T; Thu, 13 May 2021 22:40:02 +0200 Message-ID: <26e0536a8f0c16f53002b045cb7e9a30a1e8a09e.camel@telenet.be> From: Maxime Devos Date: Thu, 13 May 2021 22:39:45 +0200 In-Reply-To: References: Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-pggHsW0EOlNpigA66VFn" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1620938402; bh=utKkrWUYbxFejb9bPr5JmaDvNkULXHiqFR6lCDcg4As=; h=Subject:From:To:Date:In-Reply-To:References; b=s3rqA0DL15DphmZ6rAdP0kRrG664ZG/orzlKwkPMqSB+ojziSQQ5eVQsIjIYdT5h2 TfV6nReQQNzYRkbMgXlMAfhBR8NEIsa4XNxTAmJE9IIZUCa29Bln9OJ4Lk4FhMD+pr 7QPKRmlCt7wMTJUlRXxA6S5W88+aKByfy7dBg2Mc9Z7m0GBirgCr+MVpHn52tXWubA fWs2i8h2Mlzdd2Z0bZ5bW5UWvMHwiMOfacuaFJiA9F39M+FyrlsfXS/Gxu4KxwXBCZ eiUro3pKCM2gtxVOsFi+2XwZdOe3GijZ5yKF2mCXy4JKo05OT0oXef2joAq41UGo6G 31QxZpGgWyu3g== X-Spam-Score: -0.7 (/) 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 (-) --=-pggHsW0EOlNpigA66VFn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Taylan Kammer schreef op do 13-05-2021 om 21:14 [+0200]: > Hi Maxime, >=20 > I believe that match conflating () and #nil is the right thing, > even if the current implementation does it unintentionally. >=20 > Those two values should be considered "the same" in most situations > even though (eqv? #nil '()) is false. Conflating #nil and () is reasonable for my use case, though this conflation should be documented. > In fact I think they should be equal? to each other. It feels > wrong that (equal? '(foo . #nil) '(foo . ())) evaluates to false, > even though both arguments represent the list '(foo). The guile manual has some information on this. (6.24.2.1 Nil, under 6.24.2 Emacs Lisp). > Please note that #nil is not ever supposed to be used intentionally. I know, but ... > It's there purely as an Elisp compatibility trick, and the only time > Scheme could should receive it is when receiving data generated by > Elisp code. For instance when Elisp code generates a list, it would > be terminated by #nil. (Which is why I think it should equal? '().) I have been porting some common lisp code to Guile Scheme. I replaced '() with #nil, which allows me to largely ignore whether Lisp nil is used as end-of-list or as boolean for now (I'm in the process of replacing it with '() or #f where appropriate). Being able to directly refer to #nil, to perform equality checks like (eq? #f #nil) --> #f, (eq? '() #nil) --> #f, ... can be useful for writing Scheme code that could be called from both elisp and Scheme when the compatibility isn't transparent. For example, suppose (ice-9 match) actual= ly did not conflate #nil and () (which is what I initially thought; I expected (ice-9 match) to compare atoms with eqv?), then the following code ... ;; Somewhat contrived (untested), but based on some real code (define=20 (match-lambda ((_ . stuff) stuff) (() 0))) ... would need to be rewritten to something like ... ;; Somewhat contrived (untested), but based on some real code (define=20 (match-lambda ((_ . stuff) stuff) (() 0) (#nil 0))) Also, consider the 'case' syntax. Greetings, Maxime. --=-pggHsW0EOlNpigA66VFn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYJ2OkxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7n9CAP9lTwPh87IbXbJo1IUdfB01PtTF X1ZM4OaJRr4Fol27KwEA3FsAk/qEirTQtCvOvJRG4YbQpu0Y5gDNO0IpybEt1g8= =c75C -----END PGP SIGNATURE----- --=-pggHsW0EOlNpigA66VFn-- From unknown Sat Jun 14 00:09:53 2025 X-Loop: help-debbugs@gnu.org Subject: bug#48318: (ice-9 match) does not allow distinguishing between () and #nil Resent-From: Taylan Kammer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 13 May 2021 21:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48318 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: Maxime Devos , 48318@debbugs.gnu.org Received: via spool by 48318-submit@debbugs.gnu.org id=B48318.16209409181915 (code B ref 48318); Thu, 13 May 2021 21:22:02 +0000 Received: (at 48318) by debbugs.gnu.org; 13 May 2021 21:21:58 +0000 Received: from localhost ([127.0.0.1]:44462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhImL-0000Uo-Kl for submit@debbugs.gnu.org; Thu, 13 May 2021 17:21:57 -0400 Received: from mail-ej1-f50.google.com ([209.85.218.50]:47030) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lhImK-0000UY-5s for 48318@debbugs.gnu.org; Thu, 13 May 2021 17:21:56 -0400 Received: by mail-ej1-f50.google.com with SMTP id u21so41759180ejo.13 for <48318@debbugs.gnu.org>; Thu, 13 May 2021 14:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=KBuOUfMqxQuvKOexsu4bzuWkmqr65+RRWiBgNCMpc9s=; b=Ro7S8zhXawdxvVFj/gGMLMR0y1iqso1qq/7fu08JYgcqB6ccAK5hPvQKR/AEwqpxnB 8YdQTbPPldrzumEtAxPEZYZ0dFpLwSY8Xf90ewee4tslHq9K/abMlYv1hOLv4F0gtNWh BpEkdf7RW+0WNsMFfHt6/qFRWA2sue1MS1Gy5b4c054OH3Nl5VFyekbVvKD1HG+fUiQa p/ihev38ODabpl1jJNS/NK8zEf0SXSFatFx62ouCBAnz3I0lb5Q+LPqxukrM8V10AVkI SqLd1EjywU4CnlVWx/JzAjThTvh99JLLhPOcJrKr6mBdep6TM/hqaL+NtHMKHHBnW3Ne SGVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=KBuOUfMqxQuvKOexsu4bzuWkmqr65+RRWiBgNCMpc9s=; b=HqJURys1B4gNR/KTsKrj7EP18+8we0XUblo6Xchat0972EUWGiM0W1yIxPvSJsvHba Fokw5/l+ziYStzE7lXDFcxPQ26eok+WJBrOf1YXRC44M3dKJgwX4b1N9C/csHfrEQsh5 gIY1tLRfHMVrA6vQxWnTaPvk30rc+vx1Z/VqoJbjUG6B5ZCt5JAqG2GX+ZKqSgROnCGX y+Z4OvA73/6fLVMvyh5N4RkfjrCx7UJZHkdj58TMCpGgOVPdkMBvY6dnVWVw15fWdbYD BpSocxWgZqn/pJhNaX9NfHA4UbFTPmJm/oYi44DPRlmEvbF4jZat/gSPc7Dr/GqJbwoT bpFA== X-Gm-Message-State: AOAM531D8YbeJXD/qYm57qGoB3l2X1Nz32lZ1gWhVE/SwY71jLslDjLn v6Q8vlaxjuk3dlLOoQwSM9h9R9um58NbKg== X-Google-Smtp-Source: ABdhPJxcU8zw51C579rM9M/q9mduM+6ECo0jwIe3J4rr/5gOP+UVAqrP88YP9t8VtnyyImfHhkwKFw== X-Received: by 2002:a17:907:f91:: with SMTP id kb17mr44809970ejc.521.1620940910071; Thu, 13 May 2021 14:21:50 -0700 (PDT) Received: from [192.168.178.20] (b2b-109-90-125-150.unitymedia.biz. [109.90.125.150]) by smtp.gmail.com with ESMTPSA id ga28sm2428446ejc.20.2021.05.13.14.21.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 May 2021 14:21:49 -0700 (PDT) References: <26e0536a8f0c16f53002b045cb7e9a30a1e8a09e.camel@telenet.be> From: Taylan Kammer Message-ID: <6c3a61c2-0449-9f7c-a978-b034803bcebd@gmail.com> Date: Thu, 13 May 2021 23:21:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <26e0536a8f0c16f53002b045cb7e9a30a1e8a09e.camel@telenet.be> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) 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 13.05.2021 22:39, Maxime Devos wrote: > Taylan Kammer schreef op do 13-05-2021 om 21:14 [+0200]: >> Hi Maxime, >> >> I believe that match conflating () and #nil is the right thing, >> even if the current implementation does it unintentionally. >> >> Those two values should be considered "the same" in most situations >> even though (eqv? #nil '()) is false. > > Conflating #nil and () is reasonable for my use case, > though this conflation should be documented. Agree, it should definitely be documented. >> In fact I think they should be equal? to each other. It feels >> wrong that (equal? '(foo . #nil) '(foo . ())) evaluates to false, >> even though both arguments represent the list '(foo). > > The guile manual has some information on this. > (6.24.2.1 Nil, under 6.24.2 Emacs Lisp). Good catch. I see it mentions that equal? is expected to be transitive, so if (equal? #nil '()) and (equal? #nil #f) were both true, (equal? '() #f) would have to be too, which would be wrong for a Scheme implementation. We could however make it equal? to just one of the two without making equal? non-transitive. And if we're going to do that, I think the empty list would be the better choice, because of the role it plays in the structure of lists. Without any data to verify this, I'd say that situations where #nil surprises programmers by not being equal? to '() are likely to come up much more often than cases where it surprises programmers by not being equal? to #f. The parallel between equal?-ness and external representation also comes to mind. I think it's not a concrete rule, but there's the general expectation that two objects are equal? if their external representation is the same, which is the case for (foo . #nil) and (foo . ()), which would both be canonically represented as (foo). We could also go in the other direction and make Scheme's write procedure output (foo . #nil) as (foo . #nil), but I think that would be less desirable. >> Please note that #nil is not ever supposed to be used intentionally. > I know, but ... >> It's there purely as an Elisp compatibility trick, and the only time >> Scheme could should receive it is when receiving data generated by >> Elisp code. For instance when Elisp code generates a list, it would >> be terminated by #nil. (Which is why I think it should equal? '().) > > I have been porting some common lisp code to Guile Scheme. I replaced > '() with #nil, which allows me to largely ignore whether Lisp nil is used > as end-of-list or as boolean for now (I'm in the process of replacing it > with '() or #f where appropriate). Exciting! I guess that's one feasible extra use-case for #nil, but as you noted it yourself, it's probably best to rewrite the code to eliminate all the assumptions that the end-of-list object is false as a Boolean. > Being able to directly refer to #nil, to perform equality checks like > (eq? #f #nil) --> #f, (eq? '() #nil) --> #f, ... can be useful for writing > Scheme code that could be called from both elisp and Scheme when the > compatibility isn't transparent. For example, suppose (ice-9 match) actually > did not conflate #nil and () (which is what I initially thought; I expected > (ice-9 match) to compare atoms with eqv?), then the > following code ... > > ;; Somewhat contrived (untested), but based on some real code > (define > (match-lambda > ((_ . stuff) stuff) > (() 0))) > > ... would need to be rewritten to something like ... > > ;; Somewhat contrived (untested), but based on some real code > (define > (match-lambda > ((_ . stuff) stuff) > (() 0) > (#nil 0))) Indeed. > Also, consider the 'case' syntax. Case is defined in terms of eqv? in the standards so I guess it should differentiate between #nil and (). Unlike match, which does pattern matching on lists. > Greetings, > Maxime. > - Taylan