ndrop
Input Stack:
|
⇨ | Output Stack:
|
Remove the top N items from the stack. Unlike :drop which removes only one item, this operator can remove multiple items at once. This is useful for stack cleanup operations and discarding intermediate results during complex expression building.
Parameters¶
- ...: The stack items to potentially remove (at least N items should be present)
- n: Number of items to remove from the top of the stack (non-negative integer)
Behavior¶
- Item removal: Removes the top N items from the stack (N = 0 removes nothing)
- Stack preservation: Items below the top N remain unchanged on the stack
- Boundary handling: If N exceeds available items, removes all available items
- Error handling: Throws exception if N parameter is missing
Examples¶
Removing no items (N = 0):
a,0,:ndrop
Pos | Input | Output |
---|---|---|
0 | 0 | a |
1 | a |
Removing 2 items from the stack:
a,b,c,2,:ndrop
Pos | Input | Output |
---|---|---|
0 | 2 | a |
1 | c | |
2 | b | |
3 | a |
Requesting to remove more items than available (removes all 3 available):
a,b,c,4,:ndrop
Pos | Input | Output |
---|---|---|
0 | 4 | |
1 | c | |
2 | b | |
3 | a |
Error case (missing N parameter):
,:ndrop
Warning
Throws an exception due to missing the N
parameter.