4 Macros in Honu
4.1 Honu syntax
A good concrete syntax for honu macros is still under development.
4.2 Low Level Racket Interface
A Honu macro can be defined in Racket using define-honu-syntax.
Defines name to be a honu macro that uses function as the
syntax transformer. function should accept two parameters, the first is
the syntax tree that follows the macro name in the current input and the second
related to the current context but for now is not used.
function should return 3 values using values.
a new syntax object that corresponds to the computation performed by the macro
the rest of the input syntax that is to be parsed
a boolean, #t or #f, that tells the parser whether or not to immediately return the current expression or to continue parsing.
Macro’s should use syntax-parse to pattern match on their input although this is not strictly necessary. Honu provides the syntax class honu-expression from honu/core/parse that will re-invoke the honu parser and return a single expression. The result of using honu-expression can be accessed with the result attribute.
The definition of the for form for Honu.
(define-honu-syntax honu-for (lambda (code context) (syntax-parse code #:literal-sets (cruft) #:literals (honu-= honu-in) [(_ iterator:id honu-= start:honu-expression honu-to end:honu-expression honu-do body:honu-expression . rest) (values #'(for ([iterator (in-range start.result end.result)]) body.result) #'rest #t)] [(_ iterator:id honu-in stuff:honu-expression honu-do body:honu-expression . rest) (values #'(for ([iterator stuff.result]) body.result) #'rest #t)])))