Skip to content

Instantly share code, notes, and snippets.

@jkugiya
Created October 3, 2014 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkugiya/98b523a6ab03e9e4d107 to your computer and use it in GitHub Desktop.
Save jkugiya/98b523a6ab03e9e4d107 to your computer and use it in GitHub Desktop.
はじめてのClojure勉強会#5 unlessを実装
(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