[comp.lang.forth] Control structures

wmb@MITCH.ENG.SUN.COM (08/24/90)

> >                  BEGIN     BL WORD DUP COUNT  " )IF"  $=  <>
> >                  WHILE     COUNT EVALUATE        POSTPONE IF
> >                          BL WORD COUNT EVALUATE  POSTPONE ELSE

> This approach does not compile the component words into the dictionary
> but stores them as strings -- which are looked up in the dictionary
> each time the word executes.

Not so.  Each string is evaluated the first time that it is encountered,
and since compile state is in effect, the evaluation results in the
compilation of the word.

> This example was intended to determine the extent to
> which the proposed ANSI Standard provides analogs to the traditional
> Forth tools for controlling compilation. Apparently the tools have not
> (yet?) been included in the proposed Standard.

There is indeed a weakness in this area, but this example does not expose it.
The weakness is exposed if there is a delay between the time that the
"word to be compiled" is determined and the time that it is compiled.

In traditional Forth, you can tick a word, store the cfa in a variable,
and later comma that stored cfa.

In ANS Forth, you can store the name of the word, and later EVALUATE that
name to compile the word.  However, the search order might have changed in
the interim, or that word name might have been redefined, in which case you
might not compile the intended word.

The root of the problem is that the mapping from a name to an execution
token is not time-invariant.

Mitch