"Words are the fundamental unit of code in Factor, analogous to functions or procedures in other languages. Words are also objects, and this concept forms the basis for Factor's meta-programming facilities. A word consists of several parts:"
{ $list
"a word name,"
"a vocabulary name,"
"a definition, specifying the behavior of the word when executed,"
"Words are organized into named vocabularies, stored in a global variable."
{ $subsection vocabularies }
"A word is said to be " { $emphasis "interned" } " if it is a member of the vocabulary named by its vocabulary slot. Otherwise, the word is " { $emphasis "uninterned" } "."
$terpri
"Words whose names are known at parse time -- that is, most words making up your program -- can be referenced in source code by stating their name. However, the parser itself, and sometimes code you write, will need to create look up words dynamically."
"Parsing words add definitions to the current vocabulary. When a source file is being parsed, the current vocabulary is initially set to " { $vocab-link "scratchpad" } ". The current vocabulary may be changed with the " { $link POSTPONE: IN: } " parsing word (see " { $link "vocabulary-search" } ")."
"There are two approaches to creating word definitions:"
{ $list
"using parsing words at parse time,"
"using defining words at run-time."
}
"The latter is a more dynamic feature that can be used to implement code generation and such, and in fact parse-time defining words are implemented in terms of run-time defining words."
"Executing a primitive invokes native code in the Factor runtime. Primitives cannot be defined through Factor code. Compiled definitions behave similarly to primitives in that the interpreter jumps to native code upon encountering them."
{ $subsection primitive? }
{ $subsection primitive } ;
ARTICLE: "deferred" "Deferred words and mutual recursion"
{ $subsection POSTPONE: DEFER: }
{ $subsection undefined? }
{ $subsection undefined } ;
ARTICLE: "undefining" "Undefining words"
{ $subsection POSTPONE: FORGET: }
{ $subsection forget }
{ $subsection interned? } ;
ARTICLE: "declarations" "Declarations"
"Declarations give special behavior to a word. Declarations are parsing words that set a word property in the most recently defined word."
$terpri
"The first declaration specifies the time when a word runs. It affects both interpreted and compiled definitions."
{ $subsection POSTPONE: parsing }
"The remaining declarations only affect compiled definitions. They do not change evaluation semantics of a word, but instead declare that the word follows a certain contract, and thus may be compiled differently."
{ $warning "If a generic word is declared " { $link POSTPONE: foldable } ", all methods must satisfy the contract, otherwise unpredicable behavior will occur." }
"The stack effect of the above two words is designed so that it is most convenient when " { $snippet "name" } " is a literal pushed on the stack right before executing this word."
$terpri
"The following properties are set by the library:"