Gforth had had NEXTNAME ( c-addr u - ) since the beginning. Its
effect is that the next execution of a defining word uses c-addr u for
the name and does not try to parse it from the input stream. This is
useful for creating words with names that have been created in the
program.
I have never liked the stateful interface of NEXTNAME: there is some
global (or, at best, user) storage that contains the name, and there
is also a deferred word that tells the word-creating word what to do
in order to get the name of the word.
A more recent (since Gforth-0.6) alternative to using NEXTNAME is to
use EXECUTE-PARSING, which is somewhat cleaner (the word-creating word
just parses the name, no deferred word in header-creation necessary),
but has its own limitations; e.g., the name must not contain white
space (whereas NEXTNAME does not have this limitation).
And I have finally been bitten by this interface (and our
implementation of this interface): For the defining word LOCALE:
(which defines, unsurprisingly, a locale), I wanted to make it such
that it creates the locale only if it does not exist already. But
LOCALE: is also called from a word that passes the name through
NEXTNAME to LOCALE:.
Unfortunately, the implementation of NEXTNAME hooks into the header
creation of defining words, not into the name parsing of the defining
word, so I cannot just check the name and only then call the
header-creation stuff. So instead I changed the part of the code that >actually clled NEXTNAME, but that did not affect direct invocations of >LOCALE:; for those I just documented the behaviour, which is more
cumbersome than I like.
I guess we will deal with the problem at a later stage, but it will
probably require quite a bit of changes in Gforth.
Anyway, the bottom line is: stateful interfaces eventually bite you.
- anton
In article <2026Jan5.105209@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
I think that the solution is the other way around. If you have to have >CONSTANT that takes a string from the stack
A more recent (since Gforth-0.6) alternative to using NEXTNAME is to
use EXECUTE-PARSING, which is somewhat cleaner (the word-creating word
just parses the name, no deferred word in header-creation necessary),
but has its own limitations; e.g., the name must not contain white
space (whereas NEXTNAME does not have this limitation).
ciforth solution use SAVE / RESTORE
and SET-SRC. (instead of EXECUTE-PARSING)
: :CONSTANT SAVE SET-SRC CONSTANT RESTORE ;
EXECUTE-PARSING is readily defined, but you will hardly ever use it:
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 54 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 19:29:02 |
| Calls: | 742 |
| Files: | 1,218 |
| D/L today: |
6 files (8,794K bytes) |
| Messages: | 184,913 |
| Posted today: | 1 |