Next: , Previous: Syntax-Rules, Up: Syntax


4.9.4 Macro Primitives

— Function: procedure->syntax proc

Returns a macro which, when a symbol defined to this value appears as the first symbol in an expression, returns the result of applying proc to the expression and the environment.

— Function: procedure->macro proc
— Function: procedure->memoizing-macro proc
— Function: procedure->identifier-macro

Returns a macro which, when a symbol defined to this value appears as the first symbol in an expression, evaluates the result of applying proc to the expression and the environment. The value returned from proc which has been passed to PROCEDURE->MEMOIZING-MACRO replaces the form passed to proc. For example:

          (defsyntax trace
            (procedure->macro
             (lambda (x env) `(set! ,(cadr x) (tracef ,(cadr x) ',(cadr x))))))
          
          (trace foo) == (set! foo (tracef foo 'foo)).

PROCEDURE->IDENTIFIER-MACRO is similar to PROCEDURE->MEMOIZING-MACRO except that proc is also called in case the symbol bound to the macro appears in an expression but not as the first symbol, that is, when it looks like a variable reference. In that case, the form passed to proc is a single identifier.

— Special Form: defsyntax name expr

Defines name as a macro keyword bound to the result of evaluating expr, which should be a macro. Using define for this purpose may not result in name being interpreted as a macro keyword.