3 ms·
> Also, "Function" would be inaccurate because they are not mathematical functions but procedures or "subroutines" (the "standard" word in the middle of the sev
by steego 9y ago
> Also, "Function" would be inaccurate because they are not mathematical functions but procedures or "subroutines" (the "standard" word in the middle of the seventies).
From the paper: "Each word wi defines a transition function between machine states w_i: S → S" where S is...
> represented by a state S = (D,R,H,c), which contains
two stacks: a data evaluation pushdown stack D (data
stack) holds values for manipulation, and a return address
pushdown stack R (return stack) assists with return pointers
and subroutine calls. These are accompanied by a heap or
random memory access buffer H, and a program counter c.
Maybe I'm missing something. If I wrote an implementation where state comprised two immutable lists for the stacks and an immutable map for the heap, wouldn't that capture the semantics of words in as a pure function?
- lmkg 9y agoThat's not saying that the Word is a function in the programming sense. It's saying that, if you're doing static analysis of a program, there is a mathematical function that models the Word's behavior. In particular, it's doing the 'standard' trick where any computer program can be modeled as a function whose input is the entire computer (and possibly outside resources like the network), and whose output is that computer updated with any state changes that might have occurred. But that function that describes the word's behavior on the computer isn't the same as the word itself. The word's input is the few words under it on the stack, and its input is something that goes on the stack. The function's input is the entire stack, and its input gets fed into the next function. You're correct that you could right an implementation that reifies this concept, if you're so inclined. But that's still not the same thing. The 'function' is still on the meta-language level, not the language level where the word is.
- MaxBarraclough 9y ago> If I wrote an implementation where state comprised two immutable lists for the stacks and an immutable map for the heap, wouldn't that capture the semantics of words in as a pure function? A good point that slipped my mind. One can interpret Forth as modifying a stack, or, just as valid, interpret it as mapping one stack to another. Implementation detail is just that.