Generic word introspection
Factor handbook » The language » Objects » Generic words and methods

Prev:Custom method combination


In most cases, generic words and methods are defined at parse time with GENERIC: (or some other parsing word) and M:.

Sometimes, generic words need to be inspected or defined at run time; words for performing these tasks are found in the generic vocabulary.

The set of generic words is a class which implements the Definition protocol:
generic

generic? ( object -- ? )


New generic words can be defined:
define-generic ( word combination effect -- )

define-simple-generic ( word effect -- )


Methods can be added to existing generic words:
create-method ( class generic -- method )


Method definitions can be looked up:
lookup-method ( class generic -- method )

?lookup-method ( class generic -- method/f )


Finding the most specific method for an object:
effective-method ( generic -- method )


A generic word contains methods; the list of methods specializing on a class can also be obtained:
implementors ( class/classes -- seq )


Low-level word which rebuilds the generic word after methods are added or removed, or the method combination is changed:
make-generic ( word -- )


Low-level method constructor:
<method> ( class generic -- method )


Methods may be pushed on the stack with a literal syntax:
M\


See also
Printing definitions