Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; defmac (define macro) and defsmac (define simple macro) are like defun,
- ;;; but they define the function as a macro instead of as an expr. They are
- ;;; less powerful then defining a macro directly (for example, they cannot be
- ;;; used to define macros with arbitrarily many arguments) but are easier to
- ;;; use. For example,
- ;;;
- ;;; (defsmac f (x y) (foo (bar x) (bar y)))
- ;;;
- ;;; causes f to be defined as a macro in such a way that every call (f e1 e2)
- ;;; will expand to (foo (bar e1) (bar e2)) before it is evaluated.
- (defun defsmac macro (args)
- (defsmac1 (cadr args) (caddr args) (cdddr args)))
- (defun defsmac1 (name formals body)
- `(defun ,name macro (app)
- ,(defsmac2 formals
- (cond ((cdr body) (cons 'progn body))
- (t (car body))))))
- (defun defsmac2 (formals body)
- `(sublis ,(defsmac3 formals 1) (quote ,body)))
- (defun defsmac3 (formals n)
- (cond ((null formals) nil)
- (`(cons (cons (quote ,(car formals)) (car ,(defsmac4 n)))
- ,(defsmac3 (cdr formals) (1+ n))))))
- (defun defsmac4 (n) (cond ((= n 0) 'app) ((list 'cdr (defsmac4 (1- n))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement