A quotation is an anonymous function (a value denoting a snippet of code) which can be used as a value and called using the Fundamental combinators
Quotation literals appearing in source code are delimited by square brackets, for example [ 2 + ]
; see Quotation syntax
for details on their syntax.
Quotations form a class of objects:
quotation? ( object -- ? )
A more general class is provided for methods to dispatch on that includes quotations, curry
, and compose
Quotations evaluate sequentially from beginning to end. Literals are pushed on the stack and words are executed. Details can be found in Stack machine model
. Words can be placed in wrappers to suppress execution: Wrappers
Quotations implement the Sequence protocol
, and existing sequences can be converted into quotations:
>quotation ( seq -- quot )
1quotation ( obj -- quot )
Although quotations can be treated as sequences, the compiler will be unable to reason about quotations manipulated as sequences at runtime. Compositional combinators
are provided for runtime partial application and composition of quotations.