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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jun 9 02:36:57 EDT 2014

There's not currently a way to attach structure-type properties to
classes (as opposed to objects).

I don't seem any immediate technical problems with adding support for
properties on classes, but there are design questions --- such as whether
and how a class's properties apply to subclasses --- that we'd have to
sort out if attaching properties to classes seems useful enough.

At Thu, 5 Jun 2014 12:14:46 -0400, "Alexander D. Knauth" wrote:
> 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
> 
> 
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.