Created
March 5, 2018 19:31
-
-
Save winny-/5f2c199dc83d40f486cbf66e0ab12fd9 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
1 | |
120 | |
==== but the following will fail ==== | |
fact: contract violation | |
expected: natural? | |
given: -5 | |
in: the 1st argument of | |
(-> natural? natural?) | |
contract from: (function fact) | |
blaming: /tmp/ex.rkt | |
(assuming the contract is correct) | |
at: /tmp/ex.rkt:3.18 | |
==== this runs because the above exception is caught ==== |
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
#lang racket | |
(define/contract (fact n) | |
(-> exact-nonnegative-integer? exact-nonnegative-integer?) | |
(if (zero? n) | |
1 | |
(* n (fact (sub1 n))))) | |
(displayln (fact 0)) | |
(displayln (fact 5)) | |
(displayln "==== but the following will fail ====") | |
(displayln (with-handlers ([exn:fail:contract? exn-message]) | |
(fact -5))) | |
(displayln "==== this runs because the above exception is caught ====") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment