Created
June 1, 2010 19:50
-
-
Save fogus/421387 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
(defcontractedfn1 sqr | |
"Calculates the square of a number." | |
([n] | |
:requires | |
(number? n) | |
(not (zero? n)) | |
:body | |
(* n n) | |
:ensures | |
(pos? %))) | |
;;;;;; OR | |
(defcontractedfn2 sqr | |
"Calculates the square of a number." | |
([n] | |
:requires | |
(number? n) | |
(not (zero? n)) | |
:ensures | |
(pos? %) | |
:body | |
(* n n))) | |
;;;;;; OR | |
(defcontractedfn3 sqr | |
"Calculates the square of a number." | |
([n] | |
:requires | |
number? | |
(not (zero? n)) | |
:ensures | |
pos? | |
:body | |
(* n n))) | |
(sqr 0) | |
; java.lang.AssertionError: Assert failed: (not (zero? n)) | |
(sqr 7) | |
;=> 49 | |
(sqr -7) | |
;=> 49 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I see what you mean. Nothing will happen if
*assert*
is set tofalse
. In fact that pre and post conditions will not even be generated.