[racket] How to get arity of make-object? Found answer

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Jun 6 14:20:46 EDT 2014

You are correct. The case lambda will accept 1 2 or 3 args. The construction process may not accept 1 arg tomorrow




On Jun 6, 2014, at 2:18 PM, Asumu Takikawa <asumu at ccs.neu.edu> wrote:

> On 2014-06-06 13:31:17 -0400, Matthias Felleisen wrote:
>> I think we can get them in this sense:
>> 
>>>> (arity-includes? (procedure-arity (case-lambda [(x) x][(x y) x][(x y z) x])) 1)
>>> #t
>>>> (arity-includes? (procedure-arity (case-lambda [(x) x][(x y) x][(x y z) x])) 3)
>>> #t
>>>> (arity-includes? (procedure-arity (case-lambda [(x) x][(x y) x][(x y z) x])) 4)
>>> #f
>> 
>> but I agree that it is of questionable value. -- Matthias
> 
> I'm not sure this predicate, if implemented, can return useful results.
> To make this more concrete, consider the following interaction:
> 
>  -> (require racket/date)
>  -> (define base-class%
>       (class object%
>         (super-new)
>         (init x y z)))
>  -> (define weird-class%
>       (class base-class%
>         (if (= (date-week-day (current-date)) 5)
>             (super-new)
>             (super-new [x 1]))))
> 
> Today (since it's Friday), the `weird-class%` class will take three init
> arguments. If you try this tomorrow, it should take two init arguments.
> 
> Even worse, the class could change the number of init arguments it takes
> based on the parity of the millisecond field, a random coin-flip, or by
> doing face recognition with your webcam.
> 
> It might be that the arity actually will have changed from the time of
> the predicate call to the actual use of the constructor.
> 
> Cheers,
> Asumu



Posted on the users mailing list.