Skip to content

ndrop

Input Stack:
n: Int
...
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

  1. Item removal: Removes the top N items from the stack (N = 0 removes nothing)
  2. Stack preservation: Items below the top N remain unchanged on the stack
  3. Boundary handling: If N exceeds available items, removes all available items
  4. Error handling: Throws exception if N parameter is missing

Examples

Removing no items (N = 0):

a,0,:ndrop
PosInputOutput
0 0 a
1 a

Removing 2 items from the stack:

a,b,c,2,:ndrop
PosInputOutput
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
PosInputOutput
0 4
1 c
2 b
3 a

Error case (missing N parameter):

,:ndrop

Warning

Throws an exception due to missing the N parameter.

  • :drop - Remove single item from stack (N = 1 equivalent)
  • :nlist - Create list from N items (complementary operation)
  • :list - Remove all items to create list
  • :swap / :over - Reorder items instead of removing them