[racket-dev] Providing macro definitions for BSL programs

From: Nadeem Abdul Hamid (nadeem at acm.org)
Date: Sat Sep 4 22:37:48 EDT 2010

> See `first-order->higher-order'.

Yep. That does the trick.
Thanks,
--- nadeem


>
> At Sat, 4 Sep 2010 17:00:52 -0400, Nadeem Abdul Hamid wrote:
>> Ah, thank you. Now, how about this definition:
>>
>> (define-syntax (my-macro stx)
>>   (syntax-case stx (->)
>>     [(_ (func arg ...) -> rslt)
>>      #`(length (cons func (list arg ...)))]))
>> (provide my-macro ->)
>>
>> i.e. my macro takes the function name, bundles in up in a structure
>> (here I just used "cons") and then maybe passes it off to something
>> else for processing (here I just used "length" for illustration).
>>
>> Now, doing something like this in the BSL file:
>>    (my-macro (reward 3) -> "bronze")
>>
>> produces:
>>   reward: this is a procedure, so it must be applied to arguments
>> (which requires using a parenthesis before the name)
>>
>>
>>
>>
>>
>> On Sat, Sep 4, 2010 at 4:42 PM, Matthias Felleisen <matthias at ccs.neu.edu>
>> wrote:
>> >
>> > You need to define and export -> . Otherwise students don't have access to
>> the specific -> in your macro.
>> >
>> > BTW, injecting macros into *sl languages demands a lot of error checking
>> because novices are easily confused.
>> >
>> >
>> >
>> >
>> > On Sep 4, 2010, at 4:37 PM, Nadeem Abdul Hamid 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
>> >
>> >
>> _________________________________________________
>>   For list-related administrative tasks:
>>   http://lists.racket-lang.org/listinfo/dev
>


Posted on the dev mailing list.