guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: goops C interface


From: Dirk Herrmann
Subject: Re: goops C interface
Date: Sat, 28 Oct 2000 00:48:46 +0200 (MEST)

On Fri, 27 Oct 2000, Eric Moore wrote:

> 1) do people prefer some kind of giant varargs style function that
>    defines a class, or one that takes a struct that defines it?

I'm not sure about the problems that arise from adding slots
incrementally.  I would prefer such an approach.  However, if it is
actually a bad thing to add slots incrementally to a class definition, why
not use an intermediate construct (in the simplest case a list) which is
incrementally filled with slot definitions, and to actually create a
class this intermediate construct is then passed as a parameter?

The whole process could then be split into different levels, first
creating slot descriptors, then adding these together with other data to a
class descriptor.  Finally, a class is created from such a descriptor.

SCM sd1, sd2, cd, cls;
sd1 = scm_goops_make_slot_descriptor ();
scm_goops_slot_descriptor_set_name (sd1, "slot1");
scm_goops_slot_desctiptor_set_init_value (sd1, SCM_BOOL_F);
[... further initialization of sd1]
sd2 = scm_goops_make_slot_descriptor ();
scm_goops_slot_descriptor_set_name (sd2, "slot2");
scm_goops_slot_desctiptor_set_init_value (sd2, SCM_BOOL_F);
[... further initialization of sd2]
cd = scm_goops_make_class_descriptor ();
scm_goops_class_descriptor_set_name (cd, "myclass");
scm_goops_class_descriptor_add_slot (sd1);
scm_goops_class_descriptor_add_slot (sd2);
[... further slots added to cd]
cls = scm_goops_make_class (cd);

In practice, some essential data like class names or such should be passed
as arguments directly to the scm_goops_make* functions.  (The above
example overuses the concept of incremental adding of data for the sake of
demonstrating the idea.)

The idea, however, is taken from the way guile's smobs are currently
initialized. This way extensibility is granted, since extending for
example slots does not invalidate existing code since there are only new
functions added. Readability is also quite nice, as can be seen from the
current code examples for creating new smob types.

Best regards
Dirk




reply via email to

[Prev in Thread] Current Thread [Next in Thread]