3 ms·
I was recently thinking a bit about how one could create a typed Forth-like system, by adding a 3rd parallel stack that would hold the type on the data stack, a
by js8 6y ago
I was recently thinking a bit about how one could create a typed Forth-like system, by adding a 3rd parallel stack that would hold the type on the data stack, and was used for type checking.
I really wanted to like Forth (which is very similar to Lisp/Smalltalk systems, even possibly more elegant in some respects), because of the system extensibility, but the stack errors drove me crazy. So if the system had the ability to show the types of things on the stack (or name them) while programming, that would be a big help.
Such Forth seems to be surprisingly close to Haskell (or other lambda calculus like language), which I really enjoy lately (I wouldn't go back to Lisp), but written in reverse.
- thequux 6y agoThat sounds really cool, and I'd love to see the result if/when you build it
- vidarh 6y agoA third stack is one more thing to keep track of. The simpler solution to this in many languages is type tagging. E.g. Ruby (MRI at least) uses a few bits to indicate type to avoid creating full-blown objects for small-ish integers, symbols, etc., and you'll find the same approach in many strongly typed dynamic languages.
- js8 6y agoI think you misunderstand. The 3rd stack would be parallel to data stack, and would be used during interpretation for dynamic type checking (and also completion), or during compilation to do static type checking (and also type inference).
- vidarh 6y agoI got that. The point I was making is that type tagging is an alternative to this that saves you from keeping the extra stack in sync, as well as avoids sacrificing another register as a stack pointer. It's also well trodden ground in the form of tagged unions of various forms going back at least to ALGOL 68 so there's plenty of literature on the subject.
- lebuffon 6y agoFranck done this already for you: http://www.oforth.com/ http://www.oforth.com/ Also look at another next generation concatentive language: https://8th-dev.com/ https://8th-dev.com/ Not object-oriented per se but a very comprehensive protected hi-level language/environment with "Forthy" origins.