Search code examples
arduinoforth

Why is 'DO LOOP' missing in 328eForth?


I’m trying to learning Forth directly in an embedded system and using Starting Forth by Leo Brodie as a text. The Forth version I’m using is 328eForth (a port of eforth to the ATmega328) which I’ve flashed into an Arduino Uno.

It appears that the DO LOOP words are not implemented in 328eForth - which puts a kink in my learning with Brodie. But looking at the dictionary using “WORDS” shows that a series of looping words exist e.g. BEGIN UNTIL WHILE FOR NEXT AFT EXIT AGAIN REPEAT amongst others.

My questions are as follows:

Q1 Why was DO LOOP omitted from 328eForth?

Q2 Can DO LOOP be implemented in other existing words? If so, how please and if not why? (I guess there must be a very good reason for the omission of DO LOOP...)

Q3 Can you give some commented examples of the 328eForth looping words?


Solution

  • Q1: A choice was made for a different loop construct.

    Q2: The words FOR and NEXT perform a similar function that just counts down to 0 and runs exactly the specified number of times, including zero.
    The ( n2 n1 -- ) DO ... LOOP always runs at least once, which requires additional (mental) bookkeeping. People have been complaining about that as long back as I can remember.

    Q3: The 382eforth documentation ForthArduino_1.pdf contains some examples.


    Edit: Added some exposé to Q2