[racket] contracts ->i optional keyword syntax
On Aug 27, 2014, at 11:12 AM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>
> On Aug 27, 2014, at 12:22 PM, Kevin Forchione <lysseus at gmail.com> wrote:
>
>>
>> #lang racket
>>
>> (provide (contract-out [foo
>> (-> string? list?)])
>> (rename-out (foo bar)))
>>
>> (define (foo n) (list n))
>>
>> (module+ test
>> (require (submod ".."))
>> (foo 3)
>> (bar "3”))
>>
>> Here foo violates the contract. Changing the argument to foo to “3” and the argument to bar to 3 shows that bar does not violate the contract. So the contract is bound to foo and not to the rename. Quite interesting!
>>
>
>
> contract-out attaches a contract to foo so when you can call foo on 3, you get an error.
>
> provide also exports foo as bar w/o contract, so you can call it on anything you want.
>
> This is clearly what the words of the program imply, and the semantics of the language gives it to you. No problems!
Yes, I agree. Very useful! Is there a way to attach a contract to a renamed identifier? I tried wrapping contract around a rename form and it didn’t appear to like it.
-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140827/64ce744f/attachment.html>