Factor handbook > The language > Objects > Tuples

Prev:Tuple examples
Next:Slot accessors


TUPLE: class slots... ; TUPLE: class < superclass slots ... ;

Inputs and outputs
classa new tuple class to define
slotsa list of slot specifiers

Word description
Defines a new tuple class.

The superclass is optional; if left unspecified, it defaults to tuple.

Slot specifiers take one of the following three forms:
name - a slot which can hold any object, with no attributes
{ name attributes... } - a slot which can hold any object, with optional attributes
{ name class attributes... } - a slot specialized to a specific class, with optional attributes

Slot attributes are lists of slot attribute specifiers followed by values; a slot attribute specifier is one of initial: or read-only. See Tuple slot declarations for details.

A simple tuple class:
TUPLE: color red green blue ;

Declaring slots to be integer-valued:
TUPLE: color { red integer } { green integer } { blue integer } ;

An example mixing short and long slot specifiers:
TUPLE: person { age integer initial: 0 } { department string initial: "Marketing" } manager ;

See also
tuple-class, define-tuple-class