This is an old bug I spotted before, it can be solved by inserting an extra
let
in the expansion aka

(macroexpand '(match a (par code  ...))
-> '(let ((arg a)) ....)

This is missing from atoms in match so I added that there and the
missbehavior dissapears. see the git diffed patch in this post.


On Wed, Sep 21, 2011 at 5:34 AM, Andy Wingo <[email protected]> wrote:

> Hi,
>
> Try this:
>
>  (use-modules (language tree-il) (ice-9 match))
>  (define foo (parse-tree-il '(let-values (apply (lambda () (lambda-case
> ((() #f #f #f () ()) (apply (primitive values) (const 1) (const 2))))))
> (lambda-case (((a b) #f #f #f () (#{a 134390}# #{b 134391}#)) (apply
> (primitive list) (lexical a #{a 134390}#) (lexical b #{b 134391}#)))))))
>  (match foo
>    (($ <let-values> src exp
>        ($ <lambda-case> src2 req #f #f #f () gensyms body #f))
>     #t)
>    (_
>     #f))
>  => #t
>
>  (match foo
>    (($ <let-values> src foo ;; <- rename "exp" to "foo"
>        ($ <lambda-case> src2 req #f #f #f () gensyms body #f))
>     #t)
>    (_
>     #f))
>  => #f
>
> I tried to reduce this case a bit, but didn't succeed directly, and I
> need to move on.  But what is the deal here?
>
> Andy
> --
> http://wingolog.org/
>
>
>
>
diff --git a/module/ice-9/match.scm b/module/ice-9/match.scm
index 686539b..0384f69 100644
--- a/module/ice-9/match.scm
+++ b/module/ice-9/match.scm
@@ -57,3 +57,21 @@
 ;; Note: Make sure to update `match.test.upstream' when updating this
 ;; file.
 (include-from-path "ice-9/match.upstream.scm")
+
+(define-syntax match
+  (syntax-rules ()
+    ((match)
+     (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) ...)))
+    ((match #(vec ...) (pat . body) ...)
+     (let ((v #(vec ...)))
+       (match-next v (v (set! v)) (pat . body) ...)))
+    ((match atom (pat . body) ...)
+     (let ((v atom))
+       (match-next v (atom (set! atom)) (pat . body) ...)))
+    ))
+

Reply via email to