[racket] contracts ->i optional keyword syntax
The default value is considered "inside" the contract boundary, not outside.
Robby
On Sun, Aug 24, 2014 at 2:17 AM, Kevin Forchione <lysseus at gmail.com> wrote:
>
> On Aug 23, 2014, at 10:03 PM, Kevin Forchione <lysseus at gmail.com> wrote:
>
> I’ve been trying to figure out the syntax for optional keywords in the ->i
> contract form. For example:
>
> (->i ([lst list?])
> ([#:foo ….]) ; what does this look like?
> (result list?))
>
> The mandatory domain syntax seems straightforward, but I’ve tried various
> combinations for the optional keyword that don’t appear to be correct.
>
> (->i ([lst list?])
> ([#:foo (lst) (….etc)))
> (result list?))
>
> doesn’t work for me, neither does sticking an id before or after … (lat) …
>
> Does anyone have an example of an optional keyword ->i contract? This would
> seem to be an extremely useful form, but the examples in the documentation
> do not appear to cover it. They do cover the ->* form, but not the ->i for
> that combination.
>
>
> Well, I seem to have sussed it. But I find it odd that the contract doesn’t
> appear to apply to the optional value as supplied. For example, the below
> shows a sample of ->*, and an ->i version that shows points up the issue:
>
> #lang racket
>
> (define/contract (foo x #:y y #:z (z 42))
> (->* (integer?
> #:y integer?)
> (#:z integer?)
> list?)
> (list x y z))
>
> (foo 3 #:y 1)
>
> (define/contract (bar x #:y y #:z (z 42))
> (->i ([x integer?]
> #:y (y integer?))
> (#:z (z (x y) (integer-in x y)))
> (result list?))
> (list x y z))
>
> (bar 3 #:y 5)
> (bar 3 #:y 5 #:z 4)
>
> -Kevin
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>