[racket] How to get arity of make-object?
I’m just wondering, would it be possible to make a class be a function that would be equivalent to (make-object % arg …)?
Is there a way to attach structure-type properties to classes, instead of to instances of classes?
Because if there is, then procedure-arity could work on the class.
My first instinct was to do this: (I know why it doesn’t work)
#lang racket
(define with-constructor%
(interface* ()
([prop:procedure (lambda (this . args)
(send/apply this constructor args))])
constructor
))
(define point%
(class* object% (with-constructor%)
(super-new) (inspect #f)
(init-field [x 0] [y 0])
(define/public (constructor . args)
(apply make-object this% args))
))
(define p (point% 1 2))
But this doesn’t work because it attaches the structure type properties to instances of the class instead of to the class itself.
Is there a way to attach structure-type properties to classes, instead of to instances of classes?
On Jun 5, 2014, at 11:32 AM, Roman Klochkov <kalimehtar at mail.ru> wrote:
> For any procedure I can use procedure-arity. But how to get the number of init arguments for a class?
>
> Or maybe there are any other way to make a contract, like in Guide 7.3.9, where one can compare number of arguments and arity of the function, but when using (make-object someclass ...)
> instead of the function.
>
>
> --
> Roman Klochkov
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users