Re: [racket-users] Contract on a parameter’s value as a function precondition?

Robby Findler <[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <CAL3TdOOktS+GyH46msOGPPTUuTjkcDcPw5v92doSmj1UjpD3sQ@mail.gmail.com>
I think that Scott investigated adding support to chaperones that
would make something like this work.

Robby


On Tue, Nov 22, 2016 at 10:16 PM, Alexis King <[email protected]> wrote:
> I have a function that requires a parameter be set to a value satisfying
> a particular contract, but I don’t see any direct way to specify that
> constraint using the contract system. It seems possible to emulate using
> #:pre from ->* and ->i, but this has two problems: it doesn’t produce
> very good error messages, and it doesn’t let me provide an arbitrary
> contract.
>
> The latter issue seems a little trickier to implement, since I don’t
> think there’s any specific support in Racket’s existing interposition
> layer. Neither impersonate-procedure nor impersonate-procedure* provide
> any control over the dynamic extent of the call, so it isn’t possible to
> adjust the parameterization. It’s possible to create an extremely simple
> contract that creates an entirely new procedure instead of a chaperone
> or impersonator:
>
>   (define (parameterization-> param-name param val/c)
>     (make-contract
>      #:name `(parameterization-> ,param-name
>                                  ,(contract-name val/c))
>      #:projection
>      (λ (blame)
>        (let ([blame* (blame-add-context
>                       blame #:swap? #t
>                       (format "the value of (~a)" param-name))])
>          (λ (val)
>            (λ args
>              (parameterize ([param (((contract-projection val/c) blame*)
>                                     (param))])
>                (apply val args))))))))
>
> …but this seems like it probably has some drawbacks. Is there a better
> way to do this? And in any case, would this be something useful to add
> to ->* or ->i?
>
> Alexis
>
> --
> 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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.