roll
Input Stack: |
⇨ |
Output Stack: |
Move an item from a specific position in the stack to the top. Unlike :pick which
copies an item, :roll
removes the item from its original position and places it on top.
This is useful for reorganizing the stack when you need to bring buried items to the surface.
Parameters
- ...: The current stack contents with at least (n+1) items
- n: Zero-based index of the item to move (0 = top item, 1 = second item, etc.)
Examples
Rolling the top item (index 0) - effectively a no-op:
a,0,:roll
Rolling the top item from a two-item stack:
a,b,0,:roll
Pos | Input | Output |
0 |
0 |
b |
1 |
b |
a |
2 |
a |
|
Rolling the second item (index 1) to the top:
a,b,1,:roll
Pos | Input | Output |
0 |
1 |
a |
1 |
b |
b |
2 |
a |
|
Difference from Pick
Operation |
Effect |
Stack Size Change |
:pick |
Copy item to top |
+1 (grows) |
:roll |
Move item to top |
0 (unchanged) |
- :pick - Copy (not move) item to top of stack
- :rot / :-rot - Rotate top three items
- :swap - Exchange top two items (equivalent to
1,:roll
)
- :depth - Check stack size before rolling
- :over - Copy second item (non-destructive alternative)
Since: 1.5.0