For Gauche 0.9.10

Next: , Previous: , Up: Macros   [Contents][Index]

5.4 Hybrid macros

A hybrid macro is both a macro and a procedure simultaneously. If a symbol bound to a hybrid macro appears in the first position of a form, it behaves like a macro and the form is expanded accodring to its macro expander. If a symbol appears other places, it is evaluated to a procedure at runtime.

It can realize so-called “compiler macros”—at a compile time, the macro part examines the arguments and can transform the form as desired. In all other circumstances, it behaves like a normal procedure binding, so you can pass the procedure to map, for example.

Macro: define-hybrid-syntax variable expr transformer-spec

Binds variable to both an ordinary Scheme value and a macro simultaneously. At the compile time, transformer-spec is evaluated; it must yield a macro in the the compile-time environment, and bound to variable to be used at macro expansion. At the execution time, expr is evaluated and bound to variable to be used as a run-time value.

The macro transformer can return the input form as is (that is, returns an object eq? to the input form), to indicate that it doesn’t need to expand it. In that case, Gauche compiles the form as an ordinary procedure call, to use the value of expr at run-time.

Next: , Previous: , Up: Macros   [Contents][Index]