Last active
May 25, 2018 07:15
-
-
Save lagenorhynque/c71da21d47660fdd2f8b62b47a29cff4 to your computer and use it in GitHub Desktop.
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
| ;;; unless | |
| user> (defmacro unless [cond then] | |
| `(if (not ~cond) | |
| ~then)) | |
| #'user/unless | |
| user> (macroexpand-1 '(unless foo? bar)) | |
| (if (clojure.core/not foo?) bar) | |
| ;;; case | |
| user> (defmacro case-table [k m] | |
| `(case ~k | |
| ~@(apply concat (eval m)))) | |
| #'user/case-table | |
| user> | |
| user> (def table (atom {})) | |
| #'user/table | |
| user> (swap! table assoc :foo '(hoge "foo")) | |
| {:foo (hoge "foo")} | |
| user> (swap! table assoc :bar '(hoge "bar!")) | |
| {:foo (hoge "foo"), :bar (hoge "bar!")} | |
| user> (defn hoge [s] ,,,) | |
| #'user/hoge | |
| user> | |
| user> (defn fun1 [x] | |
| (let [y (case-table x @table)] | |
| ,,,)) | |
| #'user/fun1 | |
| user> (macroexpand-1 '(case-table x @table)) | |
| (clojure.core/case x :foo (hoge "foo") :bar (hoge "bar!")) | |
| user> | |
| user> (swap! table dissoc :bar) | |
| {:foo (hoge "foo")} | |
| user> (swap! table assoc :baz '(hoge "baz!")) | |
| {:foo (hoge "foo"), :baz (hoge "baz!")} | |
| user> | |
| user> (defn fun2 [x] | |
| (let [y (case-table x @table)] | |
| ,,,)) | |
| #'user/fun2 | |
| user> (macroexpand-1 '(case-table x @table)) | |
| (clojure.core/case x :foo (hoge "foo") :baz (hoge "baz!")) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cf. マクロについて整理してみる | κeenのHappy Hacκing Blog