-(defun macrop (x)
- (and (symbolp x) (eq (binding-type (lookup-function x *environment*)) 'macro)))
-
-(defun ls-macroexpand-1 (form env)
- (if (macrop (car form))
- (let ((binding (lookup-function (car form) *environment*)))
- (if (eq (binding-type binding) 'macro)
- (apply (eval (binding-translation binding)) (cdr form))
- form))
- form))
-
-(defun compile-funcall (function args env)
- (cond
- ((symbolp function)
- (concat (lookup-function-translation function env)
- "("
- (join (mapcar (lambda (x) (ls-compile x env)) args)
- ", ")
- ")"))
- ((and (listp function) (eq (car function) 'lambda))
- (concat "(" (ls-compile function env) ")("
- (join (mapcar (lambda (x) (ls-compile x env)) args)
- ", ")
- ")"))
- (t
- (error (concat "Invalid function designator " (symbol-name function))))))
+(defun macro (x)
+ (and (symbolp x)
+ (let ((b (lookup-in-lexenv x *environment* 'function)))
+ (and (eq (binding-type b) 'macro)
+ b))))
+
+(defun ls-macroexpand-1 (form)
+ (let ((macro-binding (macro (car form))))
+ (if macro-binding
+ (apply (eval (binding-translation macro-binding)) (cdr form))
+ form)))
+
+(defun compile-funcall (function args)
+ (concat (ls-compile `#',function) "("
+ (join (mapcar #'ls-compile args)
+ ", ")
+ ")"))