HOOK:
Factor handbook » The language » Objects » Generic words and methods

Prev:GENERIC#:
Next:MATH:


Vocabulary
syntax

Syntax
HOOK: word variable ( stack -- effect )


Inputs
None

Outputs
None

Word description
Defines a new hook word in the current vocabulary. Hook words are generic words which dispatch on the value of a variable, so methods are defined with M:. Hook words differ from other generic words in that the dispatch value is removed from the stack before the chosen method is called.

Examples
USING: io namespaces ; IN: scratchpad SYMBOL: transport TUPLE: land-transport ; TUPLE: air-transport ; HOOK: deliver transport ( destination -- ) M: land-transport deliver "Land delivery to " write print ; M: air-transport deliver "Air delivery to " write print ; T{ air-transport } transport set "New York City" deliver
Air delivery to New York City


Notes
Hook words are really just generic words with a custom method combination (see Custom method combination).

See also
generic, define-generic, define-simple-generic, GENERIC:, GENERIC#:, MATH:

Definition