Created
December 16, 2012 13:55
-
-
Save jg/4307503 to your computer and use it in GitHub Desktop.
Lisp macro wizardry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro diff(expr var) | |
; (pprint "diff") | |
; (pprint expr) | |
; (pprint var) | |
;(pprint (first expr)) | |
;(pprint (second expr)) | |
;(pprint (third expr)) | |
(cond | |
; a' = 0 | |
((numberp expr) 0) | |
; x' = 1, y' = 0 | |
((symbolp expr) | |
(if (eq expr var) 1 0)) | |
; sum | |
((equal (first expr) '+) `(list '+ (diff ,(second expr) ,var) (diff ,(third expr) ,var))) | |
)) | |
(diff (+ a a) c) | |
(macroexpand '(diff (+ a a) c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment