What the hell is Forth? (2019)
blog.information-superhighway.net
What the hell is Forth? (2019)
1–10 of 138 posts
Re: What the hell is Forth? (2019)
#2Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort...
This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth.
You will feel like a different person after having done this. People will like you more. Food will taste better. You'll never be alone again, always knowing that you can re-create a fully-functional programming language from assembly within half an hour, if you needed to. It is said that people who know Forth die happy.
Re: What the hell is Forth? (2019)
#3I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life. Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort... This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth. You will feel like a different perso…
Re: What the hell is Forth? (2019)
#4I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life. Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort... This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth. You will feel like a different perso…
I've also heard it cures cancer. Any truth to this?
Re: What the hell is Forth? (2019)
#5I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life. Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort... This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth. You will feel like a different perso…
I was going to say "its main disadvantage is that the only way to find out what a piece of code does is to execute it mentally" (non-declarative) but one may say that of every language to an extent. Instead I will say it feels like using a macro-assembler for a stack VM.
Clifford Stoll, author of "The Cuckoo's Egg", in which he described how he chased a hacker, allegedly used FORTH to control a radio telescope (https://www.amazon.co.uk/gp/product/1416507787) back in the days (not sure, I might have got this nugget from the book).
Re: What the hell is Forth? (2019)
#6Reading the source code of "WAForth" (Forth for WebAssembly) really helped me learn about how WebAssembly works deep down, from the ground up.
It demonstrates the first step of what the article says about bootstrapping a Forth system, and it has some beautiful hand written WebAssembly code implementing the primitives and even the compiler and JavaScript interop plumbing. We discussed the possibility of developing a metacompiler in the reddit discussion.
I posted this stuff about WAForth and a link to a reddit discussion with its author in the hn discussion of "Ten influential programming languages (2020)":
https://news.ycombinator.com/item?id=34056735
Yes, I agree FORTH should be probably be on the list, at least if the list was a few languages longer, for as influential as it's been.
WAForth for WebAssembly is beautiful and modern!
https://github.com/remko/waforth
It's a lovingly crafted and hand written in well commented WebAssembly code, using Racket as a WebAssembly macro pre-processor.
I learned so much about WebAssembly by reading this and the supporting JavaScript plumbing.
The amazing thing is that the FORTH compiler dynamically compiles FORTH words into WebAssembly byte codes, and creates lots of tiny little WebAssembly modules dynamically that can call each other, by calling back to JavaScript to dynamically create and link modules, which it links together in the same memory and symbol address space on the fly! A real eye opener to me that it was possible to do that kind of stuff with dynamically generated WebAssembly code! It has many exciting and useful applications in other languages than FORTH, too.
Lots more discussion and links in the reddit article.
But here's the beef, jump right in:
https://github.com/remko/waforth/blob/master/src/waforth.wat
Reddit /r/Forth discussion of WAForth:
https://www.reddit.com/r/Forth/comments/zmb4eb/waforth_wasmb...
remko:
Author here
If you can't be bothered to install VS Code, you can have a look at a standalone version of the example notebook (in a 26kB self-contained page).
And if you're planning to go to FOSDEM 2023, come say hi: I'll be giving a talk there on WebAssembly and Forth in the Declarative and Minimalistic Computing devroom.
DonHopkins:
I really love your tour-de-force design and implementation of WAForth, and I have learned a lot about WebAssembly by reading it. Never before have I seen such beautiful meticulously hand written and commented WebAssembly code.
Especially the compiler and runtime plumbing you've implemented that dynamically assembles bytecode and creates WebAssembly modules for every FORTH word definition, by calling back to JavaScript code that pulls the binary bytecode of compiled FORTH words out of memory and creates a new module with it pointing to the same function table and memory.
WebAssembly is a well designed open standard that's taking over the world in a good way, and it also runs efficiently not just in most browsers and mobile smartphones and pads, but also on the desktop, servers, cloud edge nodes, and embedded devices. And those are perfect target environments for FORTH!
What you've done with FORTH and WebAssembly is original, brilliant, audacious, and eye-opening!
I'd read the WebAssembly spec before, and used and studied the Unity3D WebAssembly runtime and compiler to integrate Unity3D with JavaScript, and I also studied the AssemblyScript subset of TypeScript targeting WebAssembly and its runtime, and also Aaron Turner's awesome wasmboy WebAssembly GameBoy emulator .
I first saw your project a few years ago and linked to it in this Hacker News discussion about Thoughts on Forth Programming because I thought it was cool, but it's come a long way in three years, and I'm glad I finally took the time to read some of your code, which was well worth the investment of time.
Until reading your code, I didn't grasp that it was possible to integrate WebAssembly with JavaScript like that, and use it to dynamically generate code the way you have!
Also, the way you used Racket as a macro assembler for WebAssembly was a practical and beautiful solution to the difficult problem of writing maintainable WebAssembly code by hand.
Even for people not planning on using FORTH, WAForth is an enlightening and useful example for learning about WebAssembly and its runtime, and a solid proof of concept that it's possible to dynamically generate and run WebAssembly code on the fly, and integrate a whole bunch of tiny little WebAssembly modules together.
Playing with and reading through your well commented code has really helped me understand WebAssembly and TypeScript and the surface between them at a much deeper level. Thank you for implementing and sharing it, and continuing to improve it too!
remco:
Wow, thanks a lot, I really appreciate that! It makes me very happy that I was able to get someone to learn something about WebAssembly by reading the source code, which is exactly what I was going for.
[More links and discussion of WAForth, WebAssembly, and Forth Metacompilers:]
https://www.reddit.com/r/Forth/comments/zmb4eb/waforth_wasmb...
Re: What the hell is Forth? (2019)
#7I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life. Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort... This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth. You will feel like a different perso…
Agree with the parent, it's a language worth knowing like LISP is worth knowing, but (unlike LISP) it is not a good language choice for almost all use cases in 2023 (almost all use cases are not that memory constrained any more, even embedded systems), for the same reason you shouldn't use Perl (it is very hard to read code). I was going to say "its main disadvantage is that the only way to find out what a piece of c…
Re: What the hell is Forth? (2019)
#8I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life. Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort... This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth. You will feel like a different perso…
I've also heard it cures cancer. Any truth to this?
Re: What the hell is Forth? (2019)
#9An important lesson that many teams and orgs still haven't internalized. Maybe one day it'll be more commonly understood.
Re: What the hell is Forth? (2019)
#10I believe that any programmer should at least know a little about Forth. It's like Lisp. Just knowing about them is extremely enlightening, even if you don't use them in your daily life. Obligatory link: https://github.com/nornagon/jonesforth/blob/master/jonesfort... This well-written tutorial will have you implement a Forth in 500 lines of assembly and another 500 lines of Forth. You will feel like a different perso…
Agree with the parent, it's a language worth knowing like LISP is worth knowing, but (unlike LISP) it is not a good language choice for almost all use cases in 2023 (almost all use cases are not that memory constrained any more, even embedded systems), for the same reason you shouldn't use Perl (it is very hard to read code). I was going to say "its main disadvantage is that the only way to find out what a piece of c…