Macros

STK provides low level macros.

Note: STK macros are not the sort of macros defined in the appendix of R4RS, but rather the macros one can find in most of Lisp dialects.





`=̀13`(ndexfile(index-entry "macro" "tt" main )macroformals body)
syntax
Macro permits to create a macro. When a macro is called, the whole form (i.e. the macro itself and its parameters) is passed to the macro body. Binding association is done in the environment of the call. The result of the binding association is called the macro-expansionndexfile(index-entry "macro-expansion" "rm" aux ). The result of the macro call is the result of the evaluation of the macro expansion in the call environment.

$\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(define foo (macro f `(quote ,f)))(foo 1 2 3) (foo 1 2 3)

(define 1+ (macro form (list + (cadr form) 1)))(let ((x 1)) (1+ x)) 2






`=̀13`(ndexfile(index-entry "macro?" "tt" main )macro?obj)
procedure
Returns #t if obj is a macro, otherwise returns #f.





`=̀13`(ndexfile(index-entry "macro-expand-1" "tt" main )macro-expand-1form)
procedure
`=̀13`(ndexfile(index-entry "macro-expand" "tt" main )macro-expandform)
procedure
ndexfile(index-entry "Macro-expand-1" "tt" aux )Macro-expand-1 returns the macro expansion of form if it is a macro call, otherwise form is returned unchanged. ndexfile(index-entry "Macro-expand" "tt" aux )Macro-expand is similar to ndexfile(index-entry "macro-expand-1" "tt" aux )macro-expand-1, but repeately expand form until it is no longer a macro call. $\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(define 1- (macro form `(-  ,(cadr form) 1))) (define – (macro form `(1- ,(cadr form)))) (macro-expand-1 '(1- 10)) (- 10 1) (macro-expand   '(1- 10)) (- 10 1) (macro-expand-1 '(– 10)) (1- 10)(macro-expand   '(– 10)) (- 10 1)





`=̀13`(ndexfile(index-entry "macro-expand" "tt" main )macro-expandform)
procedure
Returns the macro expansion of form if it is a macro call, otherwise form is returned unchanged. Macro expansion continue until, the form obtained is $\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(define 1- (macro form (list '- (cadr form) 1)))(macro-expand '(1- 10)) (- 10 1)





`=̀13`(ndexfile(index-entry "macro-body" "tt" main )macro-bodymacro)
procedure
Returns the body of macro $\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(macro-body 1+)                (macro form (list + (cadr form) 1))





`=̀13`(ndexfile(index-entry "define-macro" "tt" main )define-macro(name formals) body)
macro
ndexfile(index-entry "Define-macro" "tt" aux )Define-macro is a macro which permits to define a macro more easily than with the ndexfile(index-entry "macro" "tt" aux )macro form. It is similar to the defmacro of Common Lisp [#!CLtL2!#]. $\Longrightarrow$
$\Longrightarrow$ unspecified error makeotherˆ`=̀13`


          gobblecr(define-macro (incr x) `(set! ,x (+ ,x 1)))(let ((a 1)) (incr a) a) 2

(define-macro (when test . body) `(if ,test ,@(if (null? (cdr body)) body `((begin ,@body)))))(macro-expand '(when a b)) (if a b)(macro-expand '(when a b c d)) (if a (begin b c d))

Note: Calls to macros defined by ndexfile(index-entry "define-macro" "tt" aux )define-macro are physically replaced by their macro-expansion if the variable ndexfile(index-entry "*debug*" "tt" aux )*debug* is #f (i.e. their body is ``in-lined'' in the macro call). To avoid this feature, and to ease debugging, you have to set this variable to #t. (See also [*]).