nip
Input Stack:
|
⇨ | Output Stack:
|
Remove the second item from the stack while keeping the top item. This operator provides a
convenient way to discard the item below the top without affecting the top item. It's equivalent
to the sequence :swap,:drop
but expresses the intent more clearly.
Parameters¶
- second: The item in the second position (will remain)
- top: The item on top of the stack (will be removed)
Behavior¶
- Selective removal: Removes only the second item, preserving the top
- Stack shrinkage: Reduces stack size by one
- Order preservation: Top item remains on top after operation
Examples¶
Removing the second item while keeping the top:
a,b,:nip
Pos | Input | Output |
---|---|---|
0 | b | b |
1 | a |
Equivalent Sequence¶
The :nip
operation is exactly equivalent to:
:swap,:drop
Both sequences produce the same result, but :nip
is more concise and expressive.