Given a forth stack, these are some of the basic operations to shuffle data
on the stack.
These effect of these operations can be expressed in Forth stack notation.
Stack effect notation shows how the stack looks before and after an
operation, but does not imply the operation performed. Only the quantity
and type of numbers on the stack are represented. The notation is often
placed in Forth code, but is really just a comment since the operators: ( )
are used exclusively for comments.
Where n, n1, etc. represent integer numbers.
DUP ( n -- n n ) DUPlicates the top number.
ROT ( n1 n2 n3 -- n2 n3 n1 ) ROTates. Pulls the third deep number off the
stack and pushes it on top.
SWAP ( n1 n2 -- n2 n1 ) SWAPs the top two numbers.
example code for a function called as "double-a-number":
: double-a-number ( n -- n )
>I'm new to forth, What does the dup, rot and swap functions do in forth?