[racket] Arity check

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Aug 21 08:27:47 EDT 2013

In general, the problem is undecidable: 

(define (f x) x)
(define (g x y) x)

(define (h x) (if (today-is-tuesday?) (h x 10) (h x)))

(h f)

Error? 

In specific circumstances, the compiler knows which function is called and could perform a check. By tradition, we don't but it's worth considering. Still, even then: 

(define (f x) (if (today-s-date-satisfies-fermats-last-theorem?) (car x 10) (car x)))

Is this an error or a warning? 







On Aug 21, 2013, at 4:16 AM, 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

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

Posted on the users mailing list.