Preserving combinators
Factor handbook » The language » Combinators » Dataflow combinators

Next:Cleave combinators


Sometimes it is necessary to temporarily hide values on the datastack. The dip combinators invoke the quotation at the top of the stack, hiding some number of values:
dip ( x quot -- x )

2dip ( x y quot -- x y )

3dip ( x y z quot -- x y z )

4dip ( w x y z quot -- w x y z )


The keep combinators invoke a quotation and restore some number of values to the top of the stack:
keep ( ..a x quot: ( ..a x -- ..b ) -- ..b x )

2keep ( ..a x y quot: ( ..a x y -- ..b ) -- ..b x y )

3keep ( ..a x y z quot: ( ..a x y z -- ..b ) -- ..b x y z )