Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.
Next: Class Definition Protocol, Previous: MOP Specification, Up: The Metaobject Protocol [Contents][Index]
make <class> . initargs
(method)
allocate-instance class initargs
(generic)
The applied allocate-instance
method should allocate storage for
a new instance of class class and return the uninitialized instance.
initialize instance initargs
(generic)
instance is the uninitialized instance returned by
allocate-instance
. The applied method should initialize the new
instance in whatever sense is appropriate for its class. The method’s
return value is ignored.
make
itself is a generic function. Hence the make
invocation itself can be customized in the case where the new instance’s
metaclass is more specialized than the default <class>
, by
defining a make
method that is specialized to that metaclass.
Normally, however, the method for classes with metaclass <class>
will be applied. This method calls two generic functions:
allocate-instance
allocates storage for and returns the new
instance, uninitialized. You might customize allocate-instance
,
for example, if you wanted to provide a GOOPS wrapper around some other
object programming system.
To do this, you would create a specialized metaclass, which would act as
the metaclass for all classes and instances from the other system. Then
define an allocate-instance
method, specialized to that
metaclass, which calls a Guile primitive C function (or FFI code), which
in turn allocates the new instance using the interface of the other
object system.
In this case, for a complete system, you would also need to customize a
number of other generic functions like make
and
initialize
, so that GOOPS knows how to make classes from the
other system, access instance slots, and so on.
initialize
initializes the instance that is returned by
allocate-instance
. The standard GOOPS methods perform
initializations appropriate to the instance class.
<object>
performs internal GOOPS instance initialization, and
initializes the instance’s slots according to the slot definitions and
any slot initialization keywords that appear in initargs.
<class>
calls
(next-method)
, then performs the class initializations described
in Class Definition Protocol.
Similarly, you can customize the initialization of instances of any
application-defined class by defining an initialize
method
specialized to that class.
Imagine a class whose instances’ slots need to be initialized at
instance creation time by querying a database. Although it might be
possible to achieve this a combination of #:init-thunk
keywords
and closures in the slot definitions, it may be neater to write an
initialize
method for the class that queries the database once
and initializes all the dependent slot values according to the results.
Next: Class Definition Protocol, Previous: MOP Specification, Up: The Metaobject Protocol [Contents][Index]