Shuffle words
Factor handbook > The language

Prev:Words
Next:Combinators


Shuffle words rearrange items at the top of the data stack as indicated by their stack effects. They provide simple data flow control between words. More complex data flow control is available with the Dataflow combinators and with Lexical variables.

Removing stack elements:
drop ( x -- )

2drop ( x y -- )

3drop ( x y z -- )

nip ( x y -- y )

2nip ( x y z -- z )


Duplicating stack elements:
dup ( x -- x x )

2dup ( x y -- x y x y )

3dup ( x y z -- x y z x y z )

over ( x y -- x y x )

2over ( x y z -- x y z x y )

pick ( x y z -- x y z x )


Permuting stack elements:
swap ( x y -- y x )


There are additional, more complex stack shuffling words whose use is not recommended.
Complex shuffle words