3 ms·
The article’s argument is that it’s not a stack machine because entry of a block is a barrier for accessing what’s on the stack. (AFAIK, exiting a block also i
by Someone 4y ago
The article’s argument is that it’s not a stack machine because entry of a block is a barrier for accessing what’s on the stack.
(AFAIK, exiting a block also is limited in that it can only return a single item)
You can’t do what’s typical in forths: push intermediate values, enter a loop, use and/or change intermediate values, check for end of loop, loop or exit, read intermediate values.
An example from http://www.murphywong.net/hello/simple.htm#L15 http://www.murphywong.net/hello/simple.htm#L15):
: INTEGERS ( +n -- )
1 \ Initialize i to 1 ( +n i=1 )
BEGIN \ Start loop: i is TOS ( +n i )
2DUP \ Duplicate 2 items ( +n i +n i )
< \ Is +n less than i ? ( +n i flag )
IF \ Act on flag ( +n i )
2DROP \ True: drop 2 items ( )
EXIT \ True: leave word ( )
THEN \ End IF ... THEN ( )
DUP \ DUPlicate TOS ( +n i i )
. \ Display TOS ( +n i )
1+ \ Increment TOS ( +n i=i+1 )
AGAIN \ Loop back ( +n i )
; \ End definition
Here, both the value of n and the loop counter are on the stack when entering the loop, and the loop removes them before exiting (using 2DROP)
Edit: you also can’t take multiple values from the stack in a loop, as in
111 108 108 101 72 5 0 DO EMIT LOOP
which, if I didn’t mess things up, prints “Hello”.
- garaetjjte 4y ago>AFAIK, exiting a block also is limited in that it can only return a single item Multi-value returns were added after MVP but they are supported now.