Re:Holonforth
by drivers99 on Monday September 26, 2022 @02:18PM
(#32986372)
One thing about forth in a linear file is you can define a word (word is the forth term for subroutine or function), use it in another word, and redefine the word to something else after that without affecting the previous word. (Generally the word list (dictionary) is just a linked list and you search by starting from the newest word.) So I'm curious how the hierarchical words are stored and in what order they are searched.
[ Parent
| on HN ]
One thing about forths is that you can easily change that if you want.
The simplest way to handle this is by patching the old word to jump to the new definition. If it bothers you that that leaves junk around, you can write words that compact the dictionary.
Alternatively, if you have malloc/free, itβs easy to change the dictionary to be a list of pointers to malloced word definitions, and, when defining a word whose name matches that of an already existing word, to update that pointer to point to the new definition, and then cleanup the old definition by freeing its memory. That may fragment your heap, though, and may affect performance.