From b56276c6704f9ce97b7b3ac71887fab1644c357f Mon Sep 17 00:00:00 2001 From: Pavel Panchekha Date: Sat, 2 Jan 2021 16:00:01 -0700 Subject: [PATCH] Allow variables in unquote-splicing terms I think that in general, `null-terminated?` should admit all patterns that _could_ match a list, instead of just the ones that _only_ match a list. That means that `(app f)` patterns and many others should also be valid, though those are harder to implement, so I haven't tried those yet. --- pkgs/racket-test/tests/match/examples.rkt | 5 +++++ racket/collects/racket/match/parse-quasi.rkt | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/pkgs/racket-test/tests/match/examples.rkt b/pkgs/racket-test/tests/match/examples.rkt index b7e5709579..85c231b5ac 100644 --- a/pkgs/racket-test/tests/match/examples.rkt +++ b/pkgs/racket-test/tests/match/examples.rkt @@ -785,6 +785,11 @@ [`(begin ,es ... ,en) (list es en)])) + (comp '((1 2 3 4) (6 7) (9)) + (match '(0 1 2 3 4 5 6 7 8 9) + [`(0 ,@a 5 ,@b 8 ,@c) + (list a b c)])) + (comp '(a b c) (let () diff --git a/racket/collects/racket/match/parse-quasi.rkt b/racket/collects/racket/match/parse-quasi.rkt index a944520321..eaf9802566 100644 --- a/racket/collects/racket/match/parse-quasi.rkt +++ b/racket/collects/racket/match/parse-quasi.rkt @@ -11,6 +11,7 @@ (cond [(Pair? pat) (null-terminated? (Pair-d pat))] [(GSeq? pat) (null-terminated? (GSeq-tail pat))] [(Null? pat) #t] + [(Var? pat) #t] [else #f])) ;; combine a null-terminated pattern with another pattern to match afterwards @@ -23,6 +24,12 @@ (append-pats (GSeq-tail p1) p2) (GSeq-mutable? p1))] [(Null? p1) p2] + [(Var? p1) (make-GSeq (list (list p1)) + (list #f) + (list #f) + (list #f) + p2 + #f)] [else (error 'match "illegal input to append-pats")])) (define hard-case?