> On May 5, 2017, at 11:30 PM, Daniel Prager <daniel.a.pra...@gmail.com> wrote:
> Thank-you Matthias
> That's neat!
> And yes, I can write a basic macro. By introducing #:freevar I was able to
> improve the blame situation, but the abstraction is a bit leaky ...
> (define-syntax-rule (define/tight (fn args ...)
> body ...)
> (define (fn args ...) (fn/impl args ...))
> (define/contract (fn/impl args ...)
> #:freevar fn ctc ; Directs blame to "fn/impl" rather than the
> enclosing module
> body ...)))
I am not sure what you mean by ‘leaky’. When I run this,
(define/tight [unsafe-factorial n]
(-> (and/c integer? (>=/c 0)) (and/c integer? (>=/c 0)))
(if (zero? n)
(* n (unsafe-factorial (- n 10)))))
(unsafe-factorial 5) ; Does not terminate
> unsafe-factorial: contract violation
> expected: (and/c real? (not/c negative?))
> given: -5
> in: an and/c case of
> the 1st argument of
> (and/c real? (not/c negative?)))
> (and/c real? (not/c negative?))))
> contract from: anonymous-module
> blaming: (function fn/impl)
> (assuming the contract is correct)
> at: unsaved-editor:13.15
The only thing that leaks is that >/c is actually an and/c contract — and I
will say I am rather surprised by that.
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.