[racket-dev] Providing macro definitions for BSL programs

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sat Sep 4 16:42:04 EDT 2010

Your macro template uses -> which means that the teaching language
program and your program (that defines my-macro) need to have the same
binding for ->. #lang racket provides the one from the contract
library, but that's not the one you get in the teaching language, so
the template doesn't match.

In general, the best thing to do when you have keywords like that is
to define them as syntax transformers (that signal errors when used,
things of the form "you have used the keyword outside of its context")
 and then export them with your macro. Either that or make sure you
get the right binding.

Also, you might want to consider using syntax/parse.

Robby

On Sat, Sep 4, 2010 at 3:37 PM, Nadeem Abdul Hamid <nadeem at acm.org> wrote:
> Suppose I make a "teachpack" that defines a macro:
>
> #lang racket
> ...
> (define-syntax (my-macro stx)
>  (syntax-case stx (->)
>    [(_ (func arg ...) -> rslt)
>     #`(check-expect (func arg ...) rslt)]))
> (my-macro (+ 4 5) -> 10)
> (test)
> (provide my-macro)
>
> Running this file works fine.
>
> Now, how exactly do I make this macro available to programs written in
> Beginning/Intermediate Student? Opening up a file in BSL level and
> typing:
>  (require "my-macro.rkt")
>  (my-macro (+ 4 5) -> 9)
> gives the error:
>  my-macro: bad syntax
>
> This macro is a simplification of the real thing I'm working on, but
> note that the arguments to this macro include name(s) of functions
> defined in the BSL file. I though of maybe using
> provide-higher-order-primitive, but it doesn't seem to work either.
>
> --- nadeem
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev
>


Posted on the dev mailing list.