Convert unconstrained-domain-> to chaperones.
This commit is contained in:
parent
d92c4e44e2
commit
05e714881d
|
@ -35,22 +35,33 @@
|
||||||
[(res-x ...) (generate-temporaries #'(rngs ...))])
|
[(res-x ...) (generate-temporaries #'(rngs ...))])
|
||||||
#'(let ([rngs-x (coerce-contract 'unconstrained-domain-> rngs)] ...)
|
#'(let ([rngs-x (coerce-contract 'unconstrained-domain-> rngs)] ...)
|
||||||
(let ([proj-x (contract-projection rngs-x)] ...)
|
(let ([proj-x (contract-projection rngs-x)] ...)
|
||||||
(define ctc
|
(define name
|
||||||
(make-contract
|
(build-compound-type-name 'unconstrained-domain-> (contract-name rngs-x) ...))
|
||||||
#:name
|
(define (proj wrapper)
|
||||||
(build-compound-type-name 'unconstrained-domain-> (contract-name rngs-x) ...)
|
(λ (blame)
|
||||||
#:projection
|
(let* ([p-app-x (proj-x blame)] ...
|
||||||
(λ (blame)
|
[res-checker (λ (res-x ...) (values (p-app-x res-x) ...))])
|
||||||
(let ([p-app-x (proj-x blame)] ...)
|
(λ (val)
|
||||||
(λ (val)
|
(if (procedure? val)
|
||||||
(if (procedure? val)
|
(wrapper
|
||||||
(make-contracted-function
|
val
|
||||||
|
(make-keyword-procedure
|
||||||
|
(λ (kwds kwd-vals . args)
|
||||||
|
(apply values res-checker kwd-vals args))
|
||||||
(λ args
|
(λ args
|
||||||
(let-values ([(res-x ...) (apply val args)])
|
(apply values res-checker args)))
|
||||||
(values (p-app-x res-x) ...)))
|
proxy-prop:contracted ctc)
|
||||||
ctc)
|
(raise-blame-error blame val "expected a procedure"))))))
|
||||||
(raise-blame-error blame val "expected a procedure")))))
|
(define ctc
|
||||||
#:first-order procedure?))
|
(if (and (chaperone-contract? rngs-x) ...)
|
||||||
|
(make-chaperone-contract
|
||||||
|
#:name name
|
||||||
|
#:projection (proj chaperone-procedure)
|
||||||
|
#:first-order procedure?)
|
||||||
|
(make-contract
|
||||||
|
#:name name
|
||||||
|
#:projection (proj proxy-procedure)
|
||||||
|
#:first-order procedure?)))
|
||||||
ctc)))]))
|
ctc)))]))
|
||||||
|
|
||||||
(define (build--> name doms doms-rest rngs kwds quoted-kwds rng-any? func)
|
(define (build--> name doms doms-rest rngs kwds quoted-kwds rng-any? func)
|
||||||
|
|
|
@ -60,29 +60,33 @@ v4 todo:
|
||||||
[(res-x ...) (generate-temporaries #'(rngs ...))])
|
[(res-x ...) (generate-temporaries #'(rngs ...))])
|
||||||
#'(let ([rngs-x (coerce-contract 'unconstrained-domain-> rngs)] ...)
|
#'(let ([rngs-x (coerce-contract 'unconstrained-domain-> rngs)] ...)
|
||||||
(let ([proj-x (contract-projection rngs-x)] ...)
|
(let ([proj-x (contract-projection rngs-x)] ...)
|
||||||
|
(define name
|
||||||
|
(build-compound-type-name 'unconstrained-domain-> (contract-name rngs-x) ...))
|
||||||
|
(define (projection wrapper)
|
||||||
|
(λ (blame)
|
||||||
|
(let* ([p-app-x (proj-x blame)] ...
|
||||||
|
[res-checker (λ (res-x ...) (values (p-app-x res-x) ...))])
|
||||||
|
(λ (val)
|
||||||
|
(unless (procedure? val)
|
||||||
|
(raise-blame-error blame val "expected a procedure, got ~v" val))
|
||||||
|
(wrapper
|
||||||
|
val
|
||||||
|
(make-keyword-procedure
|
||||||
|
(λ (kwds kwd-vals . args)
|
||||||
|
(apply values res-checker kwd-vals args))
|
||||||
|
(λ args
|
||||||
|
(apply values res-checker args)))
|
||||||
|
proxy-prop:contracted ctc)))))
|
||||||
(define ctc
|
(define ctc
|
||||||
(make-contract
|
(if (and (chaperone-contract? rngs-x) ...)
|
||||||
#:name
|
(make-chaperone-contract
|
||||||
(build-compound-type-name 'unconstrained-domain-> (contract-name rngs-x) ...)
|
#:name name
|
||||||
#:projection
|
#:projection (projection chaperone-procedure)
|
||||||
(λ (blame)
|
#:first-order procedure?)
|
||||||
(let ([p-app-x (proj-x blame)] ...)
|
(make-contract
|
||||||
(λ (val)
|
#:name name
|
||||||
(if (procedure? val)
|
#:projection (projection proxy-procedure)
|
||||||
(make-contracted-function
|
#:first-order procedure?)))
|
||||||
(make-keyword-procedure
|
|
||||||
(λ (kwds kwd-vals . args)
|
|
||||||
(let-values ([(res-x ...) (keyword-apply val kwds kwd-vals args)])
|
|
||||||
(values (p-app-x res-x) ...)))
|
|
||||||
(λ args
|
|
||||||
(let-values ([(res-x ...) (apply val args)])
|
|
||||||
(values (p-app-x res-x) ...))))
|
|
||||||
ctc)
|
|
||||||
(raise-blame-error blame
|
|
||||||
val
|
|
||||||
"expected a procedure")))))
|
|
||||||
#:first-order
|
|
||||||
procedure?))
|
|
||||||
ctc)))]))
|
ctc)))]))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ improve method arity mismatch contract violation error messages?
|
||||||
(if (and name
|
(if (and name
|
||||||
(not (parameter? new-val)) ;; when PR 11221 is fixed, remove this line
|
(not (parameter? new-val)) ;; when PR 11221 is fixed, remove this line
|
||||||
(procedure? new-val)
|
(procedure? new-val)
|
||||||
|
(not (proxy-of? new-val v)) ;; proxies/chaperones handle this fine
|
||||||
(not (eq? name (object-name new-val))))
|
(not (eq? name (object-name new-val))))
|
||||||
(let ([name (if (symbol? name)
|
(let ([name (if (symbol? name)
|
||||||
name
|
name
|
||||||
|
|
Loading…
Reference in New Issue
Block a user