Shuffle words
Up:
The language
,
Factor handbook
Prev:
Words
Next:
Combinators
Shuffle words rearrange items at the top of the data stack. They control the flow of data between words that perform actions.
The
Cleave combinators
,
Spread combinators
and
Apply combinators
are closely related to shuffle words and should be used instead where possible because they can result in clearer code; also, see the advice in
Factor philosophy
.
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 )
•
dupd ( x y -- x x y )
•
over ( x y -- x y x )
•
2over ( x y z -- x y z x y )
•
pick ( x y z -- x y z x )
•
tuck ( x y -- y x y )
Permuting stack elements:
•
swap ( x y -- y x )
•
swapd ( x y z -- y x z )
•
rot ( x y z -- y z x )
•
-rot ( x y z -- z x y )
•
spin ( x y z -- z y x )
•
roll ( x y z t -- y z t x )
•
-roll ( x y z t -- t x y z )