[plt-scheme] How to create a macro that's in expression position?
At Mon, 31 Mar 2003 00:33:22 -0500, "Agnes Schemelt" wrote:
> Reading through the MzScheme language manual, I found in chapter 12 a
> statement that says you can create macros that are in expression position. I
> take this to mean that, for example, a macro TRIGGER can be invoked with
> this code:
> ( 1 TRIGGER 4 )
>
> What does the macro definition look like?
>
> The best I could come up with is this, which doesn't work:
> (define-syntax (TRIGGER stx)
> (syntax-case stx ()
> (( x TRIGGER y) ...etc..)
> )
> )
>
> What's weird is that if you could get it to work, the syntax object for a
> macro in expression position is not (identifier ...) but only the identifier
> itself, which doesn't seem useful. How do you get the rest?
I don't believe that this is possible. I believe that the text you read
only refers to identifier macros. That is, you can write a macro for
trigger in this code:
(1 trigger 4)
but it would only be allowed to change the middle part of that
expression (where the word trigger is), not the 1 and the 4.
> It would be wonderful if it truly worked. And I have a suspicion
> that this is what's behind the infix syntax:
> (if (a . < . b) ..etc..)
The infix syntax is implemented at the reader level and is a different
mechanism. So, for instance, the structural equality predicate, equal?
cannot tell the difference between these two:
(equal? '(a b c) '(b . a . c))
If you were to take the car of the second argument, in fact, you'd get
the symbol 'a, not the symbol 'b.
Sorry if that's disappointing!
Robby