GNU bug report logs -
#9567
curious match bug (?)
Previous Next
Reported by: Andy Wingo <wingo <at> pobox.com>
Date: Wed, 21 Sep 2011 03:36:01 UTC
Severity: normal
Done: ludo <at> gnu.org (Ludovic Courtès)
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 9567 in the body.
You can then email your comments to 9567 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Wed, 21 Sep 2011 03:36:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Andy Wingo <wingo <at> pobox.com>
:
New bug report received and forwarded. Copy sent to
bug-guile <at> gnu.org
.
(Wed, 21 Sep 2011 03:36:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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/
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Wed, 21 Sep 2011 16:11:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 9567 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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 <at> 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/
>
>
>
>
[Message part 2 (text/html, inline)]
[match-bug.patch (text/x-patch, attachment)]
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Fri, 23 Sep 2011 14:47:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 9567 <at> debbugs.gnu.org (full text, mbox):
Could it be a feature?
(let ((pat '('a _ ...)))
(match '(a b c) (pat #t)))
=> #t
Ludo'.
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Fri, 23 Sep 2011 16:25:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 9567 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On the other hand
(let ((pat '(a _ ...)))
(match '(x y z) (pat #t)))
$1 = #t
as well,
a more canonical example of this problem (where I saw it first)
are when using 'and' e.g.
(define a '(1 2))
(match a ((and (a 2) (1 b)) (+ a b)) (_ #f))
-> #f
But with my fix you wil get the correct 3.
Now the reson are that for 'and' as well as for '$' another location a is
under the command
of an implicit (let ((a car)) ...). One could perhaps argue that this is a
bug in syntax handling but I would not think so. Anyway maybe we should
consider moving this fix upstream.
/Stefan
2011/9/23 Ludovic Courtès <ludo <at> gnu.org>
> Could it be a feature?
>
> (let ((pat '('a _ ...)))
> (match '(a b c) (pat #t)))
> => #t
>
> Ludo'.
>
>
>
>
[Message part 2 (text/html, inline)]
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Sat, 24 Sep 2011 14:52:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 9567 <at> debbugs.gnu.org (full text, mbox):
On Fri 23 Sep 2011 16:45, ludo <at> gnu.org (Ludovic Courtès) writes:
> Could it be a feature?
>
> (let ((pat '('a _ ...)))
> (match '(a b c) (pat #t)))
> => #t
`match' compiles patterns to Scheme code at macro expansion time. It
doesn't do runtime matching. Are you thinking that `pat' is being used
as a pattern? It is not:
(let ((pat '('b _ ...)))
(match '(a b c) (pat #t)))
=> #t
If it were a pattern, it would not match. It is a bug IMO.
Andy
--
http://wingolog.org/
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Sat, 24 Sep 2011 15:03:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 9567 <at> debbugs.gnu.org (full text, mbox):
Hi Alex,
We are getting the following bug in Guile:
> (use-modules (ice-9 match))
This imports your `match' library.
> (define a '(1))
> (match a (((and a 1)) a) (_ #f))
1
Here we destructured the first element from '(1).
> (define a '(1 2))
> (match a ((and (a 2) (1 b)) (+ a b)) (_ #f))
#f
Now we are trying to destructure the first two elements from '(1 2).
But it doesn't work! OTOH it does work if we rename the pattern vars:
> (match a ((and (x 2) (1 y)) (+ x y)) (_ #f))
3
Can you reproduce this bug on other Schemes? Could it be that the code
to extract vars to be bound is erroneously propagating the var bound to
the input value? Or is it a bug in Guile?
Stefan Israelsson Tampe reports that the following redefinition of
`match' fixes the problem for him:
(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) ...)))))
As you see the last case introduces a `let'.
Regards,
Andy
--
http://wingolog.org/
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Sun, 25 Sep 2011 07:01:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 9567 <at> debbugs.gnu.org (full text, mbox):
Hi Andy,
On Sun, Sep 25, 2011 at 12:01 AM, Andy Wingo <wingo <at> pobox.com> wrote:
>
> We are getting the following bug in Guile:
> [...]
>
> > (define a '(1 2))
> > (match a ((and (a 2) (1 b)) (+ a b)) (_ #f))
> #f
Yes, that's a bug - confirmed in Chibi. The
diagnosis is also correct. I've applied the
patch and updated the synthcode match.scm
and the Chibi repo.
Thanks Stefan!
--
Alex
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Sat, 15 Oct 2011 14:09:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 9567 <at> debbugs.gnu.org (full text, mbox):
Hi Alex,
Alex Shinn <alexshinn <at> gmail.com> skribis:
> On Sun, Sep 25, 2011 at 12:01 AM, Andy Wingo <wingo <at> pobox.com> wrote:
>>
>> We are getting the following bug in Guile:
>> [...]
>>
>> > (define a '(1 2))
>> > (match a ((and (a 2) (1 b)) (+ a b)) (_ #f))
>> #f
>
> Yes, that's a bug - confirmed in Chibi. The
> diagnosis is also correct. I've applied the
> patch and updated the synthcode match.scm
> and the Chibi repo.
I’m trying to update Guile’s copy from Chibi but changeset
876:528cdab3f818 in the default branch doesn’t seem to contain the fix.
What am I missing?
Thanks,
Ludo’.
Information forwarded
to
bug-guile <at> gnu.org
:
bug#9567
; Package
guile
.
(Sun, 16 Oct 2011 07:30:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 9567 <at> debbugs.gnu.org (full text, mbox):
Hi Ludovic,
2011/10/15 Ludovic Courtès <ludo <at> gnu.org>:
>
> I’m trying to update Guile’s copy from Chibi but changeset
> 876:528cdab3f818 in the default branch doesn’t seem to contain the fix.
>
> What am I missing?
"hg export 851" will show you the changes, including
the new test case. Does it not work in Guile?
On the off chance you're unfamiliar with mercurial,
did you remember to "hg update" after fetching the
changes?
--
Alex
Reply sent
to
ludo <at> gnu.org (Ludovic Courtès)
:
You have taken responsibility.
(Sun, 16 Oct 2011 16:40:01 GMT)
Full text and
rfc822 format available.
Notification sent
to
Andy Wingo <wingo <at> pobox.com>
:
bug acknowledged by developer.
(Sun, 16 Oct 2011 16:40:02 GMT)
Full text and
rfc822 format available.
Message #34 received at 9567-done <at> debbugs.gnu.org (full text, mbox):
Hi Alex,
Alex Shinn <alexshinn <at> gmail.com> skribis:
> 2011/10/15 Ludovic Courtès <ludo <at> gnu.org>:
>>
>> I’m trying to update Guile’s copy from Chibi but changeset
>> 876:528cdab3f818 in the default branch doesn’t seem to contain the fix.
>>
>> What am I missing?
>
> "hg export 851" will show you the changes, including
> the new test case. Does it not work in Guile?
Yes.
> On the off chance you're unfamiliar with mercurial,
> did you remember to "hg update" after fetching the
> changes?
Oh indeed, I had run ‘hg pull’ (I think) but not ‘hg update’.
Thanks!
Ludo’.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Mon, 14 Nov 2011 12:24:04 GMT)
Full text and
rfc822 format available.
This bug report was last modified 13 years and 170 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.