and/c: use projections more on flat-contract arguments

This commit is contained in:
AlexKnauth 2015-05-25 18:52:20 -04:00 committed by Robby Findler
parent 78ecccc2b1
commit 2b0ba444c0
3 changed files with 20 additions and 20 deletions

View File

@ -491,6 +491,11 @@
'pos 'neg)
save-file))
(context-test '("an and/c case of")
'(contract (and/c integer? positive?)
5.9
'pos 'neg))
(let* ([blame-pos (contract-eval '(make-blame (srcloc #f #f #f #f #f)
#f
(λ () 'integer?)

View File

@ -203,7 +203,7 @@
(test/spec-passed/result
'and/c-isnt
'(and (regexp-match #rx"isn't: even?"
'(and (regexp-match #rx"promised: even?"
(with-handlers ((exn:fail? exn-message))
(contract (and/c integer? even? positive?)
-3

View File

@ -138,15 +138,13 @@
(cond
[(null? predicates) val]
[else
(if ((car predicates) val)
(loop (cdr predicates) (cdr ctcs))
(raise-blame-error
blame
val
'(expected: "~s" given: "~e\n which isn't: ~s")
(contract-name ctc)
val
(contract-name (car ctcs))))])))))
(cond
[((car predicates) val)
(loop (cdr predicates) (cdr ctcs))]
[else
(define ctc1-proj (contract-projection (car ctcs)))
(define new-blame (blame-add-context blame "an and/c case of"))
((ctc1-proj new-blame) val)])])))))
(define (first-order-val-first-and-proj ctc)
(define predicates (first-order-and/c-predicates ctc))
@ -158,16 +156,13 @@
(cond
[(null? predicates) (λ (neg-party) val)]
[else
(if ((car predicates) val)
(loop (cdr predicates) (cdr ctcs))
(λ (neg-party)
(raise-blame-error
blame #:missing-party neg-party
val
'(expected: "~s" given: "~e\n which isn't: ~s")
(contract-name ctc)
val
(contract-name (car ctcs)))))])))))
(cond
[((car predicates) val)
(loop (cdr predicates) (cdr ctcs))]
[else
(define ctc1-val-first-proj (get/build-val-first-projection (car ctcs)))
(define new-blame (blame-add-context blame "an and/c case of"))
((ctc1-val-first-proj new-blame) val)])])))))
(define (and-stronger? this that)
(and (base-and/c? that)