Created
December 21, 2009 20:32
-
-
Save fogus/261214 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
(defn constrained-fn [f x] | |
{:pre [(pos? x)] | |
:post [(= % (* 2 x))]} | |
(f x)) | |
(constrained-fn #(* 2 %) 2) | |
;=> 4 | |
(constrained-fn #(float (* 2 %)) 2) | |
;=> 4.0 | |
(constrained-fn #(* 3 %) 2) | |
;=> java.lang.Exception: Assert failed: (= % (* 2 x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment