REDUCE

9.4 Support Functions for Macro Evaluation

(expand L:list FN:function): list expr
Expand is a convenient way to expand a certain type of macro. PSL supports functions like plus which accept any number of arguments. The macro plus is actually defined in terms of the binary operator plus2. For example,
    (plus 1 2 3)

expands into

    (plus2 1 (plus2 2 3))

FN should be a function which accepts two arguments, and L should be a list of values which are acceptable to FN as arguments.

    (de expand (l fn)  
      (cond ((not (pairp l)) l)  
            ((not (pairp (cdr l))) (car l))  
            (t (list fn (car l) (expand (cdr l) fn)))))  
 
    1 lisp> (dm plus (a) (expand (rest a) 'plus2))  
    plus  
    2 lisp> (macroexpand '(plus 1 2 3))  
    (plus2 1 (plus2 2 3))

(robustexpand L: list FN: function EMPTYCASE: form): list expr
If the list L is empty then EMPTYCASE is evaluated, otherwise the result of (expand L FN) is returned.