Define-Macro

(define-macro formals stmt ...)

The Define-Macro special form constructs a function and, when exported, binds it into the global syntax table. This permits modules to extend the compiler with new special forms and construct domain specific languages. The syntax of define-macro is identical to the syntax of define, when used to define a function.

examples/thunk.ms

(module "examples/thunk")

(define-macro (thunk . statements)
  `(lambda () ,@statements))

examples/later.ms

(module "examples/later")
(import "examples/thunk")

(define-macro (later . statements)
  `(spawn (thunk ,@statements)))

(export later)

Example of using examples/later from the REPL:

>> (import "examples/later")
>> (later (print "Hello, world"))
>> Hello, world

It is important to note that define-macro constructs a function which will be executed at compile time when the macro is encountered in the source, not later, when actually executing the program; debugging macros can be difficult -- it is often best to keep them simple and use them sparingly.