[racket] define/contract with default arguments

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

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)
> (x 2)
2
> (x)
self-contract violation: received 0 arguments, expected 1 non-keyword
argument
  contract on x from (function x), blaming (function x)
  contract: (-> number? number?)
        at: readline-input::69-70

 === context ===
/home/jon/bin/plt/collects/racket/contract/private/blame.rkt:58:0:
raise-blame-error
basic-checker53
/home/jon/bin/plt/collects/racket/private/misc.rkt:85:7

> (define/contract (y [a 5]) (-> number?) a)
> (y)
5
> (y 9)
self-contract violation: received 1 argument, expected 0 non-keyword
arguments
  contract on y from (function y), blaming (function y)
  contract: (-> number?)
        at: readline-input::130-131

 === context ===
/home/jon/bin/plt/collects/racket/contract/private/blame.rkt:58:0:
raise-blame-error
basic-checker61
/home/jon/bin/plt/collects/racket/private/misc.rkt:85:7




Posted on the users mailing list.