Digest #98 2020-04-12
Contributions
requestClarification - Reference implementation does not seem to cope with changes to the stack
I just noticed, having used the reference implementation of [IF]/[ELSE]/[THEN] in my own Forth system, that it keeps markers on the data stack, and hence does not work correctly if you write e.g. 1 [IF] 2 [ELSE] 3 [THEN]
. I have stared at the standard text, and it does not seem to forbid this usage; also I see that e.g. GForth makes use of [IF]...[ELSE]....[THEN]
to put values on the stack in exactly this way (and GForth has its own rather different implementation.
Assuming I've not misunderstood something here, could a warning about this limitation be added to the reference implementation until such time as it is improved?
Replies
referenceImplementation - Suggested reference implementation
Implementation with BEGIN
leaves c-addr u
on the stack.
Corrected version:
: FILL ( c-addr u char -- )
( If u is greater than zero, store char in each of u consecutive characters of memory beginning at c-addr.)
>R BEGIN
DUP 0<>
WHILE
OVER R@ SWAP C!
1 /STRING
REPEAT
2DROP
R> DROP
;
requestClarification - Reference implementation does not seem to cope with changes to the stack
This is my misreading, and an unfortunate combination of circumstances in my own code that caused me to leap to this conclusion. So please delete my previous query!