[racket] contracts ->i optional keyword syntax

From: Kevin Forchione (lysseus at gmail.com)
Date: Sun Aug 24 03:17:15 EDT 2014

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 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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140824/826b4aa8/attachment-0001.html>

Posted on the users mailing list.