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 -- )

4drop ( w x y z -- )

5drop ( v w x y z -- )

nip ( x y -- y )

2nip ( x y z -- z )

3nip ( w x y z -- z )

4nip ( v w x y z -- z )

5nip ( u v w 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 )


Duplicating stack elements deep in the stack:
dupd ( x y -- x x y )


Permuting stack elements deep in the stack:
swapd ( x y z -- y x z )

overd ( x y z -- x y x z )

rot ( x y z -- y z x )

-rot ( x y z -- z x y )

spin ( x y z -- z y x )

4spin ( w x y z -- z y x w )

rotd ( w x y z -- x y w z )

-rotd ( w x y z -- y w x z )

nipd ( x y z -- y z )

2nipd ( w x y z -- y z )

3nipd ( v w x y z -- y z )