Smart combinators - Factor Documentation (original) (raw)
A smart combinator is a macro which reflects on the stack effect of an input quotation. The combinators.smart vocabulary implements a few simple smart combinators which look at the static stack effects of input quotations and generate code which produces or consumes the relevant number of stack values.
Take all input values from a sequence:
input<sequence ( seq quot -- )
input<sequence-unsafe ( seq quot -- )
Store all output values to a sequence:
output>sequence ( quot exemplar -- seq )
output>array ( quot -- array )
Reducing the set of output values:
reduce-outputs ( quot operation -- )
map-reduce-outputs ( quot mapper reducer -- quot )
Applying a quotation to groups of elements on the stack:
append-outputs ( quot -- seq )
append-outputs-as ( quot exemplar -- seq )
Drop the outputs after calling a quotation:
Cause a quotation to act as a no-op and drop the inputs:
Preserve the inputs below or above the outputs of the quotation: preserving ( quot -- )
keep-inputs ( quot -- )
Versions of if that infer how many inputs to keep from the predicate quotation:
smart-if ( pred true false -- )
smart-when ( pred true -- )
smart-unless ( pred false -- )
Versions of if* that infer how many inputs to keep from the predicate quotation:
smart-if* ( pred true false -- )
smart-when* ( pred true -- )
smart-unless* ( pred false -- )
New smart combinators can be created by defining Macros which call infer.