Created
August 20, 2012 10:40
-
-
Save syou6162/3403043 to your computer and use it in GitHub Desktop.
何重和みたいなものをexpressionを取って簡単に書けるようにするマクロ
This file contains hidden or 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 sum [bindings expr] | |
`(reduce + (for ~bindings ~expr))) | |
(macroexpand-1 '(sum [x '(1 2 3) | |
y '(4 5 6)] | |
(+ x y))) | |
(clojure.core/reduce | |
clojure.core/+ | |
(clojure.core/for [x (quote (1 2 3)) | |
y (quote (4 5 6))] | |
(+ x y))) | |
;; \sum_{x \in {1 2 3} \sum_{y \in {4 5 6} (x + y) | |
(sum [x '(1 2 3) | |
y '(4 5 6)] | |
(+ x y)) ; 63 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment