1

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
  • 2
    It is a primitive stack-based language, having to shuffle the top-of-stack values around to get the job done is a very common need. So lots of vocabulary for it: dup, ?dup, drop, swap, over, nip, tuck, rot, -rot, Sure, convenience. – Hans Passant Feb 23 '17 at 22:15
  • @HansPassant Please see the edit, does still mean it's for convenience? – Ecir Hana Feb 23 '17 at 23:31
  • 1
    Many processors implement it. It makes sense to provide it in the language. I used a language in the 1970s that had an IMP operator. – user207421 Feb 26 '17 at 10:04

2 Answers2

7

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.

ruvim
  • 7,151
  • 2
  • 27
  • 36
0

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.

vonbrand
  • 11,412
  • 8
  • 32
  • 52