Node:Extending Guiles Primitives, Previous:Generic Function Internals, Up:Creating Generic Functions



3.5.3 Extending Guile's Primitives

When GOOPS is loaded, many of Guile's primitive procedures can be extended by giving them a generic function definition that operates in conjunction with their normal C-coded implementation. For primitives that are extended in this way, the result from the user- or application-level point of view is that the extended primitive behaves exactly like a generic function with the C-coded implementation as its default method.

The generic-capability? predicate should be used to determine whether a particular primitive is extensible in this way.

generic-capability? primitive primitive procedure
Return #t if primitive can be extended by giving it a generic function definition, otherwise #f.

Even when a primitive procedure is extensible like this, its generic function definition is not created until it is needed by a call to define-method, or until the application explicitly requests it by calling enable-primitive-generic!.

enable-primitive-generic! primitive primitive procedure
Force the creation of a generic function definition for primitive.

Once the generic function definition for a primitive has been created, it can be retrieved using primitive-generic-generic.

primitive-generic-generic primitive primitive procedure
Return the generic function definition of primitive.

primitive-generic-generic raises an error if primitive is not a primitive with generic capability, or if its generic capability has not yet been enabled, whether implicitly (by define-method) or explicitly (by enable-primitive-generic!).

Note that the distinction between, on the one hand, primitives with additional generic function definitions and, on the other hand, generic functions with a default method, may disappear when GOOPS is fully integrated into the core of Guile. Consequently, the procedures described in this section may disappear as well.