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:
Image
drop ( x -- )

Image
2drop ( x y -- )

Image
3drop ( x y z -- )

Image
4drop ( w x y z -- )

Image
5drop ( v w x y z -- )

Image
nip ( x y -- y )

Image
2nip ( x y z -- z )

Image
3nip ( w x y z -- z )

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

Image
5nip ( u v w x y z -- z )


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

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

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

Image
over ( x y -- x y x )

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

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


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


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


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

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

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

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

Image
spin ( x y z -- z y x )

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

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

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

Image
nipd ( x y z -- y z )

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

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