[plt-scheme] match library for r6rs
On Fri, 2008-05-09 at 14:21 +0200, Ballnat, Stefan wrote:
> I’m trying to find a match library for r6rs. Using the match library
> from mzlib didn’t work.
>
>
>
> Following program worked for r5rs:
>
>
>
> (module match-testing mzscheme
>
>
>
> (require (lib "plt-match.ss" "mzlib"))
>
>
>
> (match '(1 2 1)
>
> ((list a b a) (display "foo")))
>
>
>
> )
>
>
>
> Trying to write it in r6rs leads to an error message:
>
>
>
> #!r6rs
>
> (library (match-test)
>
>
>
> (export)
>
> (import (rnrs)
>
> (mzlib plt-match)
>
> )
>
>
>
> (match '(1 2 1)
>
> ((list a b a) (display "foo")))
>
> )
>
>
>
> match: no matching clause for {1 2 1}
I think this could be failing because the PLT matchers from mzlib and
scheme/match are trying to match the PLT-Scheme-Language's list type
which is immutable, but the R6RS list type being used here is mutable,
and when the mutable list is given to the matcher implemented in the
PLT-Scheme-Language, the matcher fails to find a match because it
doesn't recognize mutable lists as lists. But I'm not positive this is
the issue.
> In the Ikarus code I also found a match library that was ported to
> r6rs.
This matcher that comes with the Ikarus distribution only does (import
(ikarus)) which means it is implemented in the (ikarus) language, which
is a superset of R6RS, which means the match library depends on
functionality beyond R6RS. However, the additional dependencies are
minimal and I've already made a port of this matcher which is portable
and would run on MzScheme if it weren't for another issue related to the
one I mention in my last comment below, and I have two other different
matchers which currently do work in MzScheme, one of which is a port of
Alex Shinn's hygienic version of the Wright matcher which is most
similar to PLT's matcher:
[libraries (xitomatl AS-match) and (xitomatl smatch)]
https://code.launchpad.net/~derick-eddington/ikarus-libraries/xitomatl
> But using this library with DrScheme leads to following error message:
>
> match.ss:377:6: compile: bad syntax; function application is not
> allowed, because no #%app syntax transformer is bound
I think the reason for this error could be a bug in MzScheme's R6RS
support. I think the macro experts here can tell us. I think the issue
has to do with export levels of bindings. IIRC (rnrs) is supposed to be
imported for phase `expand' by default. The problem can be reduced to
this example, which only works in MzScheme if the (rnrs) library is
explicitly imported for phase `expand':
#!r6rs
(import (for (rnrs) run #;expand))
(define-syntax A
(let ()
(define-syntax B
(syntax-rules () [(_ x) x]))
(define (h)
(B 1))
(lambda (ignored)
(h))))
(write (A)) (newline)
ERROR=>
compile: bad syntax; function application is not allowed, because no #%
app syntax transformer is bound in: (syntax-rules () ((_ x) x))
Uncomment the `expand' in the import form, and it works.
--
: Derick
----------------------------------------------------------------