3 ms·
I would like to find the motivated time to analyze how Forth and lambda-calculus functional languages compare/connect. Each Forth word seems to be effectively a
by quantified 7y ago
I would like to find the motivated time to analyze how Forth and lambda-calculus functional languages compare/connect. Each Forth word seems to be effectively a lambda that must be connected to a correctly-typed stack, and words can themselves manipulate the stack as its own structure.
- kragen 7y agoManfred van Thun’s Joy, Christopher Diggins’s Cat, Henry Baker’s Linear Lisp.
- quantified 7y agoThanks for the pointers!
- thesz 7y agoIt is relatively easy. You can look at stack as a list: type Stack = [Int] Adding two values at top of stack is easy: add (a:b:stk) = (a+b) : stk Dropping and duping is also easy: drop (_:stk) = stk dup (x:stk) = x:x:stk double stk = add (dup stk) You can encode list using Church encoding [1] and voila! You just connected lambda calculus and stack machine (not Forth, but close). [1] https://en.wikipedia.org/wiki/Church_encoding#List_encodings https://en.wikipedia.org/wiki/Church_encoding#List_encodings Forth include more that just stack machine - return stack, vocabulary, definintions, memory, etc. This means that these simple definitions will not be as simple as above for complete Forth. But they also can be represented as Church encoded data and they still be representable in lambda calculus.