Skip to content

nip

Input Stack:
top: Any
second: Any
Output Stack:
top: Any
 

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
PosInputOutput
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.

  • :drop - Remove top item (different position)
  • :swap - Exchange positions (component of nip)
  • :over - Copy second item to top (opposite of removing)
  • :tuck - Copy top item below second (different stack growth)
  • :2over - Copy two items from deeper positions