Skip to content

tuck

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

Copy the top item to the third position on the stack. This is equivalent to the sequence :swap,:over and is useful when you need the top item to be accessible after a binary operation.

Parameters

  • top: The item currently at the top of the stack that will be copied to the third position
  • second: The item in the second position (remains unchanged)

Examples

Basic tuck operation:

a,b,:tuck
PosInputOutput
0 b b
1 a a
2 b

Equivalent sequence using swap and over:

a,b,:swap,
:over
  • :over - Copy the second item to the top
  • :swap - Exchange the top two items
  • :dup - Duplicate the top item