Digest #237 2023-11-28
Contributions
In traditional implementations, the text interpreter uses WORD and thus clobbers the buffer used by word. This can be seen with the following test:
: ctype count type ; cr bl word uno ctype
If the text interpreter does not clobber the word buffer, this test outputs "uno"; if the text interpreter uses the WORD buffer, it outputs "ctype". Here are the results for different Forth systems:
output system
uno Gforth 0.7.3, Copyright (C) 1995-2008 ...
ctype iForth-5.1-mini
uno lxf 1.6-982-823 Compiled on 2017-12-03
ctype SwiftForth x64-Linux 4.0.0-RC52 20-Sep-2022
uno VFX Forth 64 5.11 RC2 [build 0112] 2021-05-02 for Linux x64
So two systems clobber the WORD buffer in the text interpreter (as is traditional).
The reason for this request is that I fail to find any hint in the standard that the WORD buffer may be clobbered by parsing by the text interpreter. An obvious place would be 3.3.3.6, and it does mention certain circumstances when the contents of the WORD buffer may become invalid, but these circumstances do not include parsing by the text interpreter. A not so good place would be 3.4.1, but I don't find any such a provision there, either. If the standard contains such a provision, it is well hidden and that should be fixed.
If the standard does not contain such a provision, there are two options:
- Fix the systems to avoid clobbering the WORD buffer in the text interpreter
- Change the standard to allow clobbering the word buffer by parsing in the text interpreter.
Given that I have seen confused questions by users over the clobbering behaviour by some systems several times, I would prefer option 1. If you prefer option 2, make a proposal for such a change.
Replies
I don't understand what this proposal has to do with "interpreted loops" . All noforths and ciforths (Dutch Forths) have interpreted loops with using SAVE-INPUT and RESTORE-INPUT.
I don't understand what this proposal has to do with "interpreted loops" . All noforths and ciforths (Dutch Forths) have interpreted loops without using SAVE-INPUT and RESTORE-INPUT.
Some arguments against PLACE
and +PLACE
are applicable to this proposal too.
The words
{string}!
,{string}+!
, and{string}C+
are bad practice since they don't check the size of the result buffer. A better stack effect for such words is( c-addr.string u.string c-addr.buf u.buf -- )
, and throw an exception of overflow.there is no need to include these words in the standard if they can be provided as a portable library.