[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] How to instantiate a Meroon object by class name.
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] How to instantiate a Meroon object by class name. |
Date: |
Fri, 19 Aug 2005 21:47:52 +0200 |
On 8/18/05, Ed Watkeys <address@hidden> wrote:
> Hi,
>
> I'm writing a program where I'd like to instantiate a Meroon object by
> class name. Based on what I know about Meroon, it seems like the easiest
> way is to to something like this:
>
> (define (instantiate-object-by-class-name name)
> (let ((make-instance
> (eval (string->symbol
> (string-append
> "make-"
> (symbol->string name))))))
> (make-instance)))
>
> BUT make-instance requires that all fields be initialized, so this proc
> will only work with class with no fields. What I'd really like is a way to
> use the instantiate macro but specify a computed class name. A little
> macro magic could take care of that problem, but is there a better (more
> Meroonic?) way to do what I'm looking for?
>
>From a quick look at the Meroon sources:
(->Class SYMBOL) gives you the class with the given name, and
(make-maker CLASS) returns a constructor procedure (which must have
the proper arity for all initialiizers).
I have no elegant solution right now, but one way might be to use
(Class-fields CLASS) to access the fields and figure out what arguments
are needed (see also `check-conformity' in maker.scm).
cheers,
felix