[racket] Arity check
Although Racket is dynamically typed, the compiler does notice an
obvious arity mismatch, and it logs a warning.
Some ways to see warnings:
* In DrRacket, choose "Show Log" from the "View" menu, and set the
filter to "warning" (which shows all warnings) or
"warning at optimizer" (which shows only warnings from the optimizer).
* Start Racket from the command line with
racket -W warning
or
racket -W "error warning at optimizer"
to direct warnings to stderr.
(You probably don't want just `-W warning at optimizer', because that
would hide logged errors, in case there are any.)
* In Racket using XREPL,
,log warning
shows warnings.
At Wed, 21 Aug 2013 12:16:52 +0400, Roman Klochkov wrote:
>
> Why racket doesn't check arity when compiling?
>
> (define (test)
> (car 12 3))
>
> compiles and even runs. Ir raises an error only when test is called.
>
> I can have desirable result making
>
> (define-syntax car*
> (make-set!-transformer
> (λ (stx)
> (syntax-case stx ()
> [(car* x) (syntax-protect (syntax/loc stx (car x)))]
> [(car* x ...) (raise-argument-error 'car "one argument" (syntax->datum
> #'(x ...)))]
> [car* (syntax-protect (syntax/loc stx car))]))))
> (define (test)
> (car* 12 3))
>
> But it is cumbersome (I'll have to wrap every function) and I don't understand
> why compiler shouldn't see function contracts.
>
> --
> Roman Klochkov____________________
> Racket Users list:
> http://lists.racket-lang.org/users