Is it possible to give a name to a contract created with
contract-with-explanation?

To illustrate, this example:

> #lang racket
> (define has-explanation/c
>   (flat-contract-with-explanation
>    (λ (val)
>      (λ (blame)
>        (raise-blame-error blame val
>                           '(expected:
>                             "nothing would pass this"
>                             given: "~e")
>                           val)))))
> (define/contract sample-violation
>   has-explanation/c
>   42)

prints this error message:

> sample-violation: broke its own contract
>   promised: nothing would pass this
>   produced: 42
>   in: anonymous-flat-contract
>   contract from: (definition sample-violation)
>   blaming: (definition sample-violation)
>    (assuming the contract is correct)

which is wonderful, except for the "anonymous-flat-contract" part.

If I try to give it a name with rename-contract, it loses the custom error
reporting: e.g. this example:

> (define/contract sample-violation/renamed
>   (rename-contract has-explanation/c
>                    'renamed:has-explanation/c)
>   42)

prints this:

> sample-violation/renamed: broke its own contract
>   promised: renamed:has-explanation/c
>   produced: 42
>   in: renamed:has-explanation/c
>   contract from:
>       (definition sample-violation/renamed)
>   blaming: (definition sample-violation/renamed)
>    (assuming the contract is correct)


The same thing happens with flat-named-contract: e,g, this

> (define/contract sample-violation/flat-named
>   (flat-named-contract 'flat-named:has-explanation/c
>                        has-explanation/c)
>   42)

prints this:

> sample-violation/flat-named: broke its own contract
>   promised: flat-named:has-explanation/c
>   produced: 42
>   in: flat-named:has-explanation/c
>   contract from:
>       (definition sample-violation/flat-named)
>   blaming: (definition sample-violation/flat-named)
>    (assuming the contract is correct)

-- 
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 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to