Fixed bugs in contract construction examples.
svn: r17963
This commit is contained in:
parent
a4a25ba1e9
commit
137f9a3279
|
@ -1060,8 +1060,8 @@ flat contracts do not need to supply an explicit projection.
|
||||||
@defexamples[#:eval (contract-eval)
|
@defexamples[#:eval (contract-eval)
|
||||||
(define int/c
|
(define int/c
|
||||||
(simple-flat-contract #:name 'int/c #:first-order integer?))
|
(simple-flat-contract #:name 'int/c #:first-order integer?))
|
||||||
(contract 1 int/c 'positive 'negative)
|
(contract int/c 1 'positive 'negative)
|
||||||
(contract "not one" int/c 'positive 'negative)
|
(contract int/c "not one" 'positive 'negative)
|
||||||
(int/c 1)
|
(int/c 1)
|
||||||
(int/c "not one")
|
(int/c "not one")
|
||||||
(define int->int/c
|
(define int->int/c
|
||||||
|
@ -1072,14 +1072,14 @@ flat contracts do not need to supply an explicit projection.
|
||||||
#:projection
|
#:projection
|
||||||
(λ (b)
|
(λ (b)
|
||||||
(let ([domain ((contract-projection int/c) (blame-swap b))]
|
(let ([domain ((contract-projection int/c) (blame-swap b))]
|
||||||
[range ((contract-projection int/c) blame)])
|
[range ((contract-projection int/c) b)])
|
||||||
(λ (f)
|
(λ (f)
|
||||||
(if (and (procedure? f) (procedure-arity-includes? f 1))
|
(if (and (procedure? f) (procedure-arity-includes? f 1))
|
||||||
(λ (x) (range (f (domain x))))
|
(λ (x) (range (f (domain x))))
|
||||||
(raise-blame-error
|
(raise-blame-error
|
||||||
b f "expected a function of one argument, got: ~e" f)))))))
|
b f "expected a function of one argument, got: ~e" f)))))))
|
||||||
(contract "not fun" int->int/c 'positive 'negative)
|
(contract int->int/c "not fun" 'positive 'negative)
|
||||||
(define halve (contract (λ (x) (/ x 2)) int->int/c 'positive 'negative))
|
(define halve (contract int->int/c (λ (x) (/ x 2)) 'positive 'negative))
|
||||||
(halve 2)
|
(halve 2)
|
||||||
(halve 1)
|
(halve 1)
|
||||||
(halve 1/2)
|
(halve 1/2)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user