Primitives
|
Primitives
Real work - arithmetic, array access and update, copying, etc. - is done in primitives.
Each primitive is a procedure in the Self virtual machine.
In Self, primitives are named using the syntax of keyword messages,
except that the primitive name begins with an underscore. A primitive call may
appear anywhere in a method. Primitive calls are not messages - they are not
dynamically bound.
Every primitive has two forms, the simple form and one with an argument which
is a failure block. The latter's name is derived by appending IfFail: to the former's. If
the primitive fails (e.g., due to one of the arguments being of an incorrect type, or
an arithmetic error), the fail block is invoked by sending it value:With:, with the first
string argument describing the kind of failure, and the second naming the
primitive.
A primitive call is typically embedded in a method wrapper. Direct use of
primitives is considered bad style (but acceptable in limited amounts for
pedagogical purposes!).
Useful protocol
primitives primitiveList "returns a vector of primitive names"
primitives at: '_Clone' "returns a documentation string"
primtiives match: '_Clone*' "returns a vector of primitive names matching the pattern"
|