Liste des Groupes | Revenir à cu shell |
On 2024-04-17, John Ames <commodorejohn@gmail.com> wrote:I suppose it also makes it a great deal easier to have small local functions. Forth programming, as I understand it (I've only done very small tests in Forth - I've never written a "real" program) generally involves breaking code down into very small pieces. So your implementation of "foo" might involve defining words like "get_next", "double", "set_x", or whatever. (In Forth style these would probably be shorter names, and perhaps include symbols.) Your implementation of "bar" might want to re-use these same names but with different definitions. With the list of pointers design of Forth, you can just redefine these "local" words as you need to, and ignore any previous definitions.On Wed, 17 Apr 2024 21:52:06 +0200I don't know at all whether Forth does this or not, but this design
David Brown <david.brown@hesbynett.no> wrote:
>I think that when finding the definition of a word, Forth just>
searches back through the stack of definitions until it gets a hit.
And if that word definition uses other non-primitive words, it goes
backwards from where it currently is, looking only at definitions
from before the current word was defined. Is that right? And if so,
can you do "forward declarations", and mutual recursion somehow?
That's my understanding, yes; essentially, it's a consequence of the
fact that definitions are stored as a list of pointers, and re-
definitions are simply appended to the dictionary without going back
through the rest of it to update any pointers to the prior definition.
A strange design choice, but they're consistent with it.
choice allows the list to be restored to a prior state, whereby the
recent definitions are forgotten, and the old ones revealed again,
similarly to shadowed lexicals being revealed again upon the terminaton
of an inner scope.
It sounds reminiscent of the assoc list representation of the lexical
environment in a rudimentary Lisp interpreter.
Les messages affichés proviennent d'usenet.