News for hackers. Stuff that matters.
Re:Masterminds of Programming: Chuck Moore (2009) by thesz on Monday January 06, 2020 @05:31PM (#21974206)
It 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

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.

There are no comments on this comment yet.