<tt><font size=2>> I don't understand your comment. Racket supports
mutually recursive <br>
> syntax classes. Here's a little toy example:<br>
<br>
> #lang racket<br>
> (require (for-syntax syntax/parse))<br>
<br>
> (begin-for-syntax<br>
> (define-syntax-class x<br>
> (pattern i:id<br>
> #:with (flat ...)
#'(i))<br>
> (pattern l:xlist<br>
> #:with (flat ...)
#'(l.flat ...)))<br>
> (define-syntax-class xlist<br>
> (pattern (a:x ...)<br>
> #:with (flat ...)
#'(a.flat ... ...))))<br>
<br>
> (define-syntax (m stx)<br>
> (syntax-parse stx<br>
> [(_ x:x)<br>
> #'(quote (x.flat ...))]))<br>
<br>
> (m (a (b c) ((d) ((e)))))<br>
> ;; => '(a b c d e)</font></tt>
<br>
<br><font size=2 face="sans-serif">I think that this has to do with the
evaluation structure in my implementation for guile. I think that I got
it now, basically the syntax-classes</font>
<br><font size=2 face="sans-serif">syntax structures in the racket version
is defined before the parsers are defined and inside those there
is a check for syntax classes to be defined. </font>
<br><font size=2 face="sans-serif">Tricky I really need to talk with the
guile dev's about this in order to do the same as well for the guile
version. I wrongly assumed that in order to get </font>
<br><font size=2 face="sans-serif">the interface you would need the interface
of the used syntax classes.</font>
<br>
<br><tt><font size=2>> As Neil mentioned, syntax-parse does not use
racket/match; it has its <br>
> own separate (far simpler) implementation in syntax/parse/private/minimatch.<br>
</font></tt>
<br><tt><font size=2>Yes now I remembered that this is the case, I had
used guiles (ice-9 match) for those in the guile version.</font></tt>
<br><tt><font size=2>then it can makes more sense to implement the matcher
with an extensive use of syntax-parse.</font></tt>
<br>
<br><tt><font size=2>> Those are the mechanics. I'll see about adding
more syntactic support <br>
> around it, so that you don't have to do things like declare attributes
<br>
> in multiple places. But I'd prefer not to add mutability to syntax
<br>
> classes themselves.</font></tt>
<br>
<br><tt><font size=2>cool, syntax-parse in guile is kind of heavy right
now and splitting the parser into mutual files can save</font></tt>
<br><tt><font size=2>some dev pain. (On the other hand I should fix the
code to be faster)</font></tt>
<br>
<br><tt><font size=2>> A few parts actually are. But for the syntax-parse
core, figuring out <br>
> how to bootstrap it seems like more trouble than it's worth. (Unless,
of <br>
> course, the rest of Racket goes that way...)</font></tt>
<br><tt><font size=2><br>
It's just an idea. I think it would be fun to try it out though.</font></tt>
<br><tt><font size=2>/Stefan</font></tt>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Ryan Culpepper <ryan@cs.utah.edu></b>
</font>
<p><font size=1 face="sans-serif">2012-05-12 09:01</font>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Stefan Israelsson/SECRC/ABB@ABB_SECRC</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td><font size=1 face="sans-serif">dev@racket-lang.org</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re: [racket-dev] match syntax-parse</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><tt><font size=2>On 05/11/2012 06:45 AM, stefan.israelsson@se.abb.com
wrote:<br>
> Hi,<br>
><br>
> I have done two interseting things.<br>
><br>
> 1. Ported syntax-parse over to guile.<br>
> 2. Implemented racket's match completely with the help of syntax parse.<br>
><br>
> Comments about 1.<br>
><br>
> I found that the lack of possibility to define two syntax classes
that<br>
> referese to each other inferior to what<br>
> can be done although I understand the choice of to do this and if
you<br>
> define one hugh syntax class and use<br>
> syntax class parameters you will be able to implement any feature
still<br>
> but at the drawback that one need<br>
> to define one hugh syntax class.<br>
<br>
I don't understand your comment. Racket supports mutually recursive <br>
syntax classes. Here's a little toy example:<br>
<br>
#lang racket<br>
(require (for-syntax syntax/parse))<br>
<br>
(begin-for-syntax<br>
(define-syntax-class x<br>
(pattern i:id<br>
#:with (flat ...) #'(i))<br>
(pattern l:xlist<br>
#:with (flat ...) #'(l.flat
...)))<br>
(define-syntax-class xlist<br>
(pattern (a:x ...)<br>
#:with (flat ...) #'(a.flat
... ...))))<br>
<br>
(define-syntax (m stx)<br>
(syntax-parse stx<br>
[(_ x:x)<br>
#'(quote (x.flat ...))]))<br>
<br>
(m (a (b c) ((d) ((e)))))<br>
;; => '(a b c d e)<br>
<br>
> i propose instead to add syntax-class-set! and<br>
> syntax-splicing-class-set! that has the following logic:<br>
> 1. Compile all the meta data for the class as before<br>
> 2. there has to be an already defined syntax class, the declaration,<br>
> which has a logically identical set of meta data except for<br>
> the parser function<br>
> 3. If there is no syntax class defined, error about it<br>
> 4. If there the interfaces miss-matches print out what is different.<br>
> 5. if everything is ok then set! the old named parser to the new parser<br>
><br>
> With this logic one can have mutually recursively defined syntax classes<br>
> in different files a boon if I have a say.<br>
<br>
Ah, I see now. You want mutual recursion across modules, which Racket <br>
doesn't support in general.<br>
<br>
One way to do this with Racket's syntax-parse is to define the two <br>
syntax classes as thin wrappers around reified syntax classes (see the
<br>
syntax/parse/experimental/reflect module and ~reflect). Then you can <br>
create procedures that mutate the variables holding the reified syntax
<br>
classes.<br>
<br>
Those are the mechanics. I'll see about adding more syntactic support <br>
around it, so that you don't have to do things like declare attributes
<br>
in multiple places. But I'd prefer not to add mutability to syntax <br>
classes themselves.<br>
<br>
> Also I have this working in a test case (the match parser)<br>
><br>
> So theory looks kind of nice what's the problems!<br>
><br>
> 2.<br>
> I must say that syntax-parse rocks and I would suggest that we implement<br>
> the racket matcher completely with syntax parse.<br>
> To see how it can look like consider looking at the file at,<br>
><br>
> </font></tt><a href="http://gitorious.org/guile-syntax-parse/guile-syntax-parse/blobs/master/compat/racket/match.scm"><tt><font size=2>http://gitorious.org/guile-syntax-parse/guile-syntax-parse/blobs/master/compat/racket/match.scm</font></tt></a><tt><font size=2><br>
><br>
><br>
> Please look at this tomorrow CET I have a new version ready soon with<br>
> interesting addons.<br>
><br>
> The benefit: is much more hackable codebase then the current match<br>
> code-base, it's smaller for one thing.<br>
> The drawback: one must change syntax-parse to not use match code.
I<br>
> would say that this is not<br>
> that hugh investment though. And that one introduces buggs.<br>
<br>
As Neil mentioned, syntax-parse does not use racket/match; it has its <br>
own separate (far simpler) implementation in syntax/parse/private/minimatch.<br>
<br>
> Then a final question:<br>
> Should we consider implementing syntax-parse with the help of syntax-parse?<br>
<br>
A few parts actually are. But for the syntax-parse core, figuring out <br>
how to bootstrap it seems like more trouble than it's worth. (Unless, of
<br>
course, the rest of Racket goes that way...)<br>
<br>
--<br>
<br>
Thanks for the feedback, and thanks for the work you've done porting <br>
syntax-parse to Guile. It's great to hear that other people have found
<br>
it useful enough to port to other systems.<br>
<br>
Ryan<br>
</font></tt>
<br><font size=2 face="sans-serif"><br>
</font>