Cameron Moy
This library is experimental; compatibility may not be maintained.
procedure
( dynamic->d make-contract)→contract?
> (add1*42)43
> (values*42)values*: broke its own contract
promised: a number strictly greater than 42
produced: 42
in: the range of
dynamic->d
contract from: (definition values*)
blaming: (definition values*)
(assuming the contract is correct)
at: eval:4:0
1
> 11
bad-self: broke its own contract
promised: 1
produced: 2
in: the range of
the cdr of
self/c
contract from: (definition bad-self)
blaming: (definition bad-self)
(assuming the contract is correct)
at: eval:10:0
procedure
( elementof/c contractget-element)→flat-contract?
contract:contract?
bad-pair: broke its own contract
promised: integer?
produced: "hi"
in: (elementof/c integer?)
contract from: (definition bad-pair)
blaming: (definition bad-pair)
(assuming the contract is correct)
at: eval:14:0
> (might-count"hi")2
> (might-count"hi"2)2
> (might-count"hi"3)might-count: contract violation
expected: (=/c 2)
given: 3
in: the n argument of
(case->i
((-> string? integer?)
(->i
((s string?)
(n (s) (=/c (string-length s))))
(res integer?))))
contract from: (definition might-count)
blaming: top-level
(assuming the contract is correct)
at: eval:15:0
> (f)> (f)f: contract violation
expected: incr
given: 1
in: apply/c
contract from: (definition f)
blaming: top-level
(assuming the contract is correct)
at: eval:20:0
cat%/cmeow: contract violation
expected: integer?
given: 1/2
in: the 1st argument of
the meow method in
the class contract of
(class-object/c
(class/c (meow (->m integer? string?)))
(object/c (meow (->m positive? string?))))
contract from: (definition cat%)
contract on: cat%
blaming: top-level
(assuming the contract is correct)
at: eval:24:0
meow: contract violation
expected: positive?
given: -2
in: the 1st argument of
the meow method in
the object contract of
(class-object/c
(class/c (meow (->m integer? string?)))
(object/c (meow (->m positive? string?))))
contract from: (definition cat%)
contract on: cat%
blaming: top-level
(assuming the contract is correct)
at: eval:24:0
"meow meow meow meow"
procedure
class-contract:contract?make-object-contract:procedure?
bark: broke its own contract
promised: ???
produced: "meow"
in: the range of
the bark method in
the object contract of
(dependent-class-object/c
(class/c (bark (->m string? string?)))
eval:29:0)
contract from: (definition dog%)
contract on: dog%
blaming: (definition dog%)
(assuming the contract is correct)
at: eval:30:0
"woof"
procedure
( dependent-classof/c make-object-contract)→contract?
make-object-contract:procedure?
procedure
( channel*/c get-contractput-contract)→contract?
get-contract:contract?put-contract:contract?
#<thread>
x: broke its own contract
promised: integer?
produced: 11.5
in: the channel get of
(channel*/c integer? number?)
contract from: (definition x)
blaming: (definition x)
(assuming the contract is correct)
at: eval:34:0
syntax
( exercise-out id...)
racket/contract/option)"nan"))> (unchecked-foo)"nan"
> (foo)foo: broke its own contract
promised: integer?
produced: "nan"
in: the range of
the option of
(option/c (-> integer?))
contract from: (function foo)
blaming: (function foo)
(assuming the contract is correct)
at: eval:37:0
syntax
( waive-out id...)
Typically, programmers will only attach contracts at module or library boundaries with contract-out and not use contracts at the definition level with define/contract . This is because fine-grained contract boundaries cause major performance problems due to the overhead of repeated checking.
Contract annotations provide a convenient means of enabling and disabling internal contract checks as needed. For example, you may decide that for local testing you want to disable internal contract checks, but enable them during continuous integration testing.
syntax
( : idcontract-expr)
Where, and whether, that option is enabled depends on the environment variables present at run time.
If CONTRACT_EXERCISE is set, then the option is enabled by default.
If CONTRACT_EXERCISE_TEST is set, then the option is enabled by default only in the test submodule of the current file.
If neither are set, then the option is disabled by default.
sub2: broke its own contract
promised: a procedure that accepts 1 non-keyword argument
produced: #<procedure:sub2>
sub2 accepts: 0 arguments
in: (option/c
(-> number? number?)
#:tester
#<procedure:...arrow-val-first.rkt:1639:0>)
contract from: (function sub2)
blaming: (function sub2)
(assuming the contract is correct)
at: eval:42:0
> (add21.5)3.5
add2: contract violation
expected: integer?
given: 1.5
in: the 1st argument of
the option of
(option/c
(-> integer? integer?)
#:tester
#<procedure:...arrow-val-first.rkt:1639:0>)
contract from: (function add2)
blaming: top-level
(assuming the contract is correct)
at: eval:44:0