Created
October 3, 2014 07:19
-
-
Save jkugiya/98b523a6ab03e9e4d107 to your computer and use it in GitHub Desktop.
はじめてのClojure勉強会#5 unlessを実装
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 unless | |
"testを評価し、testがtrueの場合はthenを評価した値を返す。そのほかの場合はelseを評価した値を返す" | |
([test then & forms] | |
(let [[else & r] forms] | |
(if (empty? r) | |
`(if (not ~test) ~then ~else) | |
(throw (RuntimeException. "Too many arguments to unless.")))))) | |
(unless true (println "Hello World")) | |
(unless false (println "Hello World2")) | |
(unless true (println "hoge1") (println "fuga1")) | |
(unless false (println "hoge1") (println "fuga2")) | |
(unless false (println "foo") (println "bar") (println "buzz")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment