From: Taylan Kammer <taylan.kammer@gmail.com>
To: 48315@debbugs.gnu.org
Subject: bug#48315: (ice-9 match) does not suport #nil
Date: Wed, 12 May 2021 22:03:57 +0200 [thread overview]
Message-ID: <7cb7ec76-655c-e55a-17a6-99d25b3926d1@gmail.com> (raw)
In-Reply-To: <08150bbff14abca3fe8e518ea3bc758c5f492fe1.camel@telenet.be>
[-- Attachment #1: Type: text/plain, Size: 471 bytes --]
This was mind-boggling to debug!
In syntax-rules, the pattern (x ...) will match #nil, since it
matches the empty list. This can have surprising consequences.
Consider:
(define-syntax test
(syntax-rules ()
((test (x ...))
(x ...))
((test x)
x)))
(test (+ 1 2)) ; => 3
(test 123) ; => 123
(test #f) ; => #f
;; However...
(test #nil) ; error
Anyway, attached is a patch to fix the issue in match.
- Taylan
[-- Attachment #2: 0001-Fix-match-when-used-directly-on-the-nil-constant.patch --]
[-- Type: text/plain, Size: 1434 bytes --]
From b6d0b715a8bf0cc39b9fc3d46efeaf010f0d4351 Mon Sep 17 00:00:00 2001
From: Taylan Kammer <taylan.kammer@gmail.com>
Date: Wed, 12 May 2021 21:46:54 +0200
Subject: [PATCH] Fix match when used directly on the #nil constant.
* module/ice-9/match.upstream.scm (match): Make sure we don't match #nil
where we don't intend to.
Fixes <https://bugs.gnu.org/48315>.
---
module/ice-9/match.upstream.scm | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/module/ice-9/match.upstream.scm b/module/ice-9/match.upstream.scm
index b1fc371b8..3b181b75b 100644
--- a/module/ice-9/match.upstream.scm
+++ b/module/ice-9/match.upstream.scm
@@ -269,9 +269,12 @@
(match-syntax-error "missing match expression"))
((match atom)
(match-syntax-error "no match clauses"))
- ((match (app ...) (pat . body) ...)
- (let ((v (app ...)))
- (match-next v ((app ...) (set! (app ...))) (pat . body) ...)))
+ ;; The original implementation uses (app ...) not (op arg ...) here,
+ ;; but in Guile this would match #nil when it shouldn't. Failing to
+ ;; match () doesn't matter since it leads to an error anyway.
+ ((match (op arg ...) (pat . body) ...)
+ (let ((v (op arg ...)))
+ (match-next v ((op arg ...) (set! (op arg ...))) (pat . body) ...)))
((match #(vec ...) (pat . body) ...)
(let ((v #(vec ...)))
(match-next v (v (set! v)) (pat . body) ...)))
--
2.30.2
prev parent reply other threads:[~2021-05-12 20:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-09 15:57 bug#48315: (ice-9 match) does not suport #nil Maxime Devos
2021-05-12 20:03 ` Taylan Kammer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7cb7ec76-655c-e55a-17a6-99d25b3926d1@gmail.com \
--to=taylan.kammer@gmail.com \
--cc=48315@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).