Necessity of the 'rot' operator

597 Views Asked by At

Why does Forth implement the rot operator, and why does it operate on exactly the three top-most items of the stack?

Is it just for convenience or would Forth not be Turing-complete without such an instruction? Is the number of three the minimum viable option to be Turing complete?

I can imagine one could implement rot with pick or roll. So if there was none of these three operations, would it still be Turing-complete?

2

There are 2 best solutions below

0
On

Take a peek at some minimal FORTH, like jonesforth or lbForth (both are git repositories). It is rather surprising how little in terms of primitives is required to get off the ground.

0
On

This topic has nothing to do with Turing-completeness at all.

rot operation is for convenience and efficiency only. It can be defined using swap:

: rot ( a b c -- b c a ) >R SWAP R> SWAP ;

pick and roll can be also implemented using return stack (these >R and R> operations), or any other stack.

A stack can be implemented using memory access words.