Hacker News new | ask | show | jobs
by 6d65 1697 days ago
Maybe I'm not using the proper FP function term. I don't mean functions as objects that you can store or pass around or higher order functions. Just take some arguments from stack, and return some values.

What I mean is that FORTH words seem to be functions taking stuff from stack and pushing stuff back. The composition is done by chaining them together.

This probably works fine with repl driven development(same as in lisp), you find out during development that your words cannot be composed. But as mentioned by others it may make the code hard to read, having to keep the state id the stack at all times in your head.

I was thinking just adding a light syntax, ex:

let add a b = a b +

// optional type annotation

let square a = a a *

let add-square = add square

Maybe add some type inference, support for structs, match expressions. But at the core keep the low level FORTH nature, with an interpreter and compiler.

It remains to be seen if it's possible to reach a balance here. FP programmers may be disappointed this is not a proper FP language, while FORTH programers may say it's a syntax ridden abomination.

I would say with some tooling (editor support, test framework, god forbid package manager), it can be an interesting option for embedded development.

1 comments

In many forths you can have what they call locals, so your example can be:

    : add {: a b :} a b + ;