Skip to content

Instantly share code, notes, and snippets.

@gtrak
Last active December 20, 2015 19:08
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 gtrak/6180725 to your computer and use it in GitHub Desktop.
Save gtrak/6180725 to your computer and use it in GitHub Desktop.
user> (clojure.pprint/pprint (macroexpand-all '(defn constrained-fn [f x]
{:pre [(pos? x)]
:post [(= % (* 2 x))]}
(f x))))
(def
constrained-fn
(fn*
([f x]
(if
(pos? x)
nil
(do
(throw
(new
java.lang.AssertionError
(clojure.core/str
"Assert failed: "
(clojure.core/pr-str '(pos? x)))))))
(let*
[% (f x)]
(if
(= % (* 2 x))
nil
(do
(throw
(new
java.lang.AssertionError
(clojure.core/str
"Assert failed: "
(clojure.core/pr-str '(= % (* 2 x))))))))
%))))
nil
user>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment