[racket] define/contract with default arguments

From: Jon Rafkind (rafkind at cs.utah.edu)
Date: Mon May 23 16:34:25 EDT 2011

On 05/23/2011 02:14 PM, Ryan Culpepper wrote:
> On 05/23/2011 02:12 PM, Jon Rafkind wrote:
>> Is there a way to get `define/contract' to play nice with default
>> arguments? I could see how this would be an issue in general (like
>> trying to provide/contract some function defined with default arguments)
>> but I was hoping `define/contract' could set things up so it would work.
>>> (define/contract (x [a 5]) (->  number? number?) a)
> Use ->*:
> (define/contract (x [a 5]) (->* () (number?) number?) a)

Thanks that worked. I was trying to use contracts to narrow down a
failure in my code but the ultimate contract violation simply blames a
file. I had hoped to get line information for the offending caller.

Casey tells me this has to do with creating unique wrappers for each
place the function appears in the source which I'm guessing would be
slow but I can accept some performance hit.

Are there any plans to take contracts in this direction?

Posted on the users mailing list.