<html>
<body>
<font size=3>At 02:09 PM 9/9/2006, Eli Barzilay wrote:<br>
<blockquote type=cite class=cite cite="">On Sep 9, Blake McBride
wrote:<br>
> <br>
> I probably mean something like procedural macros that allow you
to<br>
> specify exactly what you want without trying to do it in some
higher<br>
> level 4th generational descriptive pattern language. I
believe<br>
> there is an SRFI about this.<br><br>
Well then, `define-syntax' does just that. When you write:<br><br>
(define-syntax foo<br>
(lambda (stx)<br>
...))<br><br>
you bind `foo' -- as a syntax -- to a syntax->syntax transformer<br>
procedure. How you implement the procedure is up to you --<br>
`syntax-rules' can construct simple transformers very easily, and<br>
`syntax-case' gives you only the pattern matching part in an easy<br>
way. But nothing prevents you to write your own body in the
above<br>
definition, and you can use the basic syntax manipulation tools<br>
(syntax-e, syntax-object->datum and
datum->syntax-object).</blockquote><br>
This is very interesting to me. If I could deal with syntax
objects<br>
the way I want and go back and forth between syntax objects<br>
and scheme objects I would be able to do anything I wanted.<br>
Once I get a good understanding of all this I could better
understand<br>
what the heck is going on with syntax-case.<br><br>
I'd like to play with this. I did try for a few minutes and
couldn't get<br>
anywhere. For starters, on entry stx, I presume, is a syntax
object<br>
representing my call. I presume the lambda must also return a
syntax object.<br>
Since stx is already a syntax object I tried:<br><br>
(define-syntax foo<br>
(lambda (stx)<br>
stx))<br><br>
(foo 6)<br><br>
and the system hangs.<br><br>
If I try:<br><br>
<br>
(define-syntax foo<br>
(lambda (stx)<br>
(syntax-object->datum stx)))<br><br>
(foo 6)<br><br>
I get: foo: return value from syntax expander was not syntax: (foo
6)<br><br>
If I try:<br><br>
<br>
(define-syntax foo<br>
(lambda (stx)<br>
(datum->syntax-object stx (car
(syntax-object->datum stx)))))<br><br>
(foo 6)<br><br>
I get: car: expects argument of type <pair>; given
foo<br><br>
So if stx represents the "foo" token, how do you get to the
6?<br><br>
Of course if I try:<br><br>
<br>
(define-syntax foo<br>
(lambda (stx)<br>
(datum->syntax-object stx (syntax-object->datum
stx))))<br><br>
(foo 6)<br><br>
I get the system hang again (I'm now full loop).<br><br>
I really like your suggestion. I just can't figure our how to get
it to work at all.<br>
(I'd prefer to avoid syntax-e since it doesn't seem to be
standard.)<br><br>
Any examples to help me grok this would be greatly appreciated.<br><br>
Blake McBride<br><br>
<br>
</font></body>
</html>