unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: 9567@debbugs.gnu.org, Andy Wingo <wingo@pobox.com>
Subject: bug#9567: curious match bug (?)
Date: Wed, 21 Sep 2011 14:15:53 +0200	[thread overview]
Message-ID: <CAGua6m0hYsApL+u=Z67wx4EWBnkcFe6zoBvuou69Vcy42oXDfQ@mail.gmail.com> (raw)
In-Reply-To: <87fwjqin5f.fsf@pobox.com>


[-- Attachment #1.1: Type: text/plain, Size: 1226 bytes --]

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 <wingo@pobox.com> 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/
>
>
>
>

[-- Attachment #1.2: Type: text/html, Size: 1741 bytes --]

[-- Attachment #2: match-bug.patch --]
[-- Type: text/x-patch, Size: 869 bytes --]

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	other threads:[~2011-09-21 12:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-21  3:34 bug#9567: curious match bug (?) Andy Wingo
2011-09-21 12:15 ` Stefan Israelsson Tampe [this message]
2011-09-23 14:45 ` Ludovic Courtès
2011-09-23 16:24   ` Stefan Israelsson Tampe
2011-09-24 14:51   ` Andy Wingo
2011-09-24 15:01 ` bug#9567: `match' bug ? Andy Wingo
2011-09-25  6:59   ` Alex Shinn
2011-10-15 14:07     ` Ludovic Courtès
2011-10-16  7:28       ` Alex Shinn
2011-10-16 16:38         ` Ludovic Courtès

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='CAGua6m0hYsApL+u=Z67wx4EWBnkcFe6zoBvuou69Vcy42oXDfQ@mail.gmail.com' \
    --to=stefan.itampe@gmail.com \
    --cc=9567@debbugs.gnu.org \
    --cc=wingo@pobox.com \
    /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).