9 ms·
The Zen of Forth
- siraben 4y agoForth also requires very minimal resources to implement which can be fun in constrained environments. Here it is on a TI-84+ calculator[0] or even a computer in The Powder Toy.[1] The runtime design is a little quirky but straightforward and you can extend the system as you execute (or even change interpreter semantics), or add optimizations such as some form of JIT quite easily. [0] https://github.com/siraben/ti84-forth https://github.com/siraben/ti84-forth [1] https://github.com/siraben/r216-forth https://github.com/siraben/r216-forth
- 082349872349872 4y agoThe "constrained environment" is the rub. In the old days, supporting a time sharing dev environment for 30 users (with 2K dedicated memory each), or getting to a functional self-hosted prompt before the floppy drive spun up to full speed, or fitting a dev environment in a single jumbo packet, etc. were not only cool, but were technically required. We have megahertz and gigabytes and "embedded" systems with MMUs and filesystems at our disposal, so I'm guessing the time when forth was a solution has long since past.
- jgerrish 4y ago> the time when forth was a solution has long since past. It depends on the problem. If it's education, I'd argue Forth still has a place. Writing a Forth compiler is a manageable project for a single developer. Restricted resource creative projects, in code and other mediums, may help with teaching and creativity. I don't have research on that, and it isn't my idea, that credit should go to multiple others.
- 082349872349872 4y agodefo. preferably up through CREATE DOES> ...
- markus_zhang 4y agoI have to say, one day I'll learn Forth for some hacking hobbies just because of Wizard's Bane.
- throwaway17_17 4y agoI have never heard of Wizard’s Bane, but that name being associated with why someone would learn Forth made me curious. So I search and find a result that says ‘where magic is volatile and he tames it with Forth.’ So, is the book ‘Wizard’s Bane’ actually focused on using Forth (or some ersatz programming language concept) to do magic? If so, that basically describes a huge part of an hypothetical RPG I’ve been designing on paper since college. Also, would you recommend the book to a fan of genre fiction?
- rperce 4y agoYes, "programming nerd's ability at programming makes him an incredible actual wizard in FantasyLand" is the book. I would recommend it!
- throwaway17_17 4y agoThanks, that description checks a whole bunch of my-favorite-things boxes.
- markus_zhang 4y agoNo it only superficialily mentions Forth and its characteristics. But it's very cool!
- throwaway17_17 4y agoI should have edited my comment to say programming language in general instead of forth specifically. It’s more the idea of using programming to do/control magic that I think sounds like a great premise.
- shagie 4y ago
- throwaway17_17 4y agoI regularly see Forth related material appear on HN. I love a lot of the concepts that get brought up in these article’s comments, particularly those that discuss the often small and personalized implementations of Forth that appear ubiquitous among those interested in Forth. However there doesn’t seem to be anyone who considers it a viable language for actual programming and a large portion of that seems to come from the personal implementations coupled with the proliferation of custom DSL’s that are reputed to spring up in any Forth program. As a person working on a programming language design that is a little forth-like in presentation (it’s not stack-based), is it just the anecdotal experience of Forth that leads to the seeming incompatibility with producing complex software? Or does this seem to be inherent in Forth’s minimal syntax design (similar discussions also happen in Lisp discussions)?
- csande17 4y agoI haven't done much with Forth, so take this with a grain of salt. Most corporate software development uses languages like Java, C#, Ruby, and Python that are all very similar to one another. Sure, some of them use different punctuation, but the basic tools you use to solve problems all involve putting pretty much the same words in pretty much the same order. It's easy for someone with one language to quickly pick up another. Forth's syntax immediately pushes it into the "weird languages" category because almost all of the words are in a different order. "1 + 1" is now "1 1 +". That sets it far enough apart from Python/Ruby/Java/etc that a tech company isn't going to use it unless they feel really strongly about it. (AFAIK there isn't any big corporate push for Forth like there is for Go and Rust and stuff.) The main audience for Forth is therefore hobbyists. I think the main reason why you see lots of handmade Forth implementations is because Forth is really easy to implement. It's a fun hobby project. And because Forth is simple, its community biases towards people who like writing simple software. If you want to write complex software in a weird language, you'll probably gravitate towards a complex language like Haskell or something.
- shagie 4y agoThat 1 1 + isn't too different (to me) from (+ 1 1) which has a different sort of beauty to it. Incidentally, the oldest surviving language on a unix system uses this syntax (and predates C): https://en.wikipedia.org/wiki/Dc_(computer_program) https://en.wikipedia.org/wiki/Dc_(computer_program) http://webarchive.loc.gov/all/20100506231949/http://cm.bell-labs.com/cm/cs/who/dmr/hist.html http://webarchive.loc.gov/all/20100506231949/http://cm.bell-... > When the PDP-11 arrived, B was moved to it almost immediately. In fact, a version of the multi-precision `desk calculator' program dc was one of the earliest programs to run on the PDP-11, well before the disk arrived. However, B did not take over instantly. Only passing thought was given to rewriting the operating system in B rather than assembler, and the same was true of most of the utilities. Even the assembler was rewritten in assembler. This approach was taken mainly because of the slowness of the interpretive code. Of smaller but still real importance was the mismatch of the word-oriented B language with the byte-addressed PDP-11. The main advantage of Forth is that it can be put in some very small places and run impressively fast. http://www.ultratechnology.com/chips.htm http://www.ultratechnology.com/chips.htm https://en.wikichip.org/wiki/novix/nc4016 https://en.wikichip.org/wiki/novix/nc4016 > NC4016 (formerly NC4000) was a 16-bit stack machine microprocessor designed by Novix in 1985 primarily for the Forth programming language. The NC4016 directly executes the primitives of the high-level Forth programming language. The NC4016 was capable of executing typical Forth programs as much as 20 times faster than the Motorola 68000. Novix also offered the NC4000 Small C Compiler which was compatible with the NC4016 microprocessor. > In 1988, the NC4016 design was licensed and improved by Harris Semiconductor which later rebranded the chip as the RTX2000, a radiation hardened version suitable for spacecrafts use. https://en.wikipedia.org/wiki/RTX2010 https://en.wikipedia.org/wiki/RTX2010 ( https://news.ycombinator.com/item?id=8611274 https://news.ycombinator.com/item?id=8611274 ) > The RTX2010, manufactured by Intersil, is a radiation hardened stack machine microprocessor which has been used in numerous spacecraft.
- eatonphil 4y agoTo me, the Zen of Forth is JONESFORTH. https://github.com/nornagon/jonesforth/blob/master/jonesforth.S https://github.com/nornagon/jonesforth/blob/master/jonesfort...
- amalgamated_inc 4y agoI second this. Typing that in was one of the most transcendental computing experiences of my life.
- chombier 4y agoWorth the read, thank you very much.
- squeaky-clean 4y agoOne of my favorite games was written in Forth. STARFLIGHT, released in 1986 for IBM PC. (Though most of my playtime is on the Sega Genesis port). It fit on two 360K floppy disks and managed to have 270 star systems and 800 fully explorable planets (well, the gas giants would kill you if you landed on them). Forth was one of the first languages I learned because I looked up what languages my favorite games used. I knew some C/C++ and that was the most common answer. But when I saw my favorite game used Forth, surely it must be an amazing language. It is a pretty amazing language. Very fun to learn and eye-opening to me at the time as to what a language could be. It was a really fun learning experience, though I've never used it for anything very complex. I can see how it could be pretty un-scalable for teams, every Forth codebase seems to turn into its own unique language. Also s-macke from HN reverse engineered the game: https://news.ycombinator.com/item?id=13506903 https://news.ycombinator.com/item?id=13506903
- hhh 4y agoI learned FORTH for a Minecraft mod called Redpower.
- RodGodKiller 4y agoWere the computers programmed in Forth?
- rtpg 4y agoI do think there's a lot of value in forth as the "easiest" high-level language to implement on resource constrained systems, but there feels like a lot of sacrificing going on to use forth when you have other choices. You can of course absorb these ideas and "get" what you want on a case-by-case in something like Python. You're one regex-replace away from turning `50 burgers` into `burgers(50)`, and then you call eval and you're good!
- bitwize 4y agoChuck Moore is pretty much the Buckminster Fuller of computing. Fuller's Dymaxion brand was associated with his idea of getting maximum utility out of minimum input (material, energy, etc.) and Forth's "energy" is much the same. Minimum runtime, minimum code, minimum CPU complexity, but combinatorially explosive power out of these things. You need to realign your brain to think in these terms -- how do I simplify my code further and make it do more? -- but people who have done this can do amazing things. (Alan Kay is the Willy Wonka of computing; one can restate Joe Armstrong's banana-gorilla-jungle problem more whimsically: with Smalltalk you go into the shop to buy a candy bar but end up getting the whole chocolate factory, with everything you need to make every kind of confection staffed by Oompa-Loompas and ready to go.)
- jng 4y agoI've always thought this really-well-written old post by Yosef Kreinin is quite enlightened regarding the reality of Forth (even if a bit snarky, as usual from him): https://yosefk.com/blog/my-history-with-forth-stack-machines.html https://yosefk.com/blog/my-history-with-forth-stack-machines...
- shaftoe444 4y agoThat was a great read
- astrobe_ 4y agoThen find all the little half-truths in that post. I think this part sums up the problem with Forth quite well: > I defined the instruction set in a couple of hours. It mapped to Forth words as straightforwardly as possible [...] but it was harder than we thought. Presumably that was partly the result of not reading "Stack Computers: the new wave" In other words: people too often confuse "simple" and "easy", think they don't need the experience of others, and then feel bad when they try and fail - and that post provides them with solace and a good excuses to quit when it happens with Forth. I don't mind them quitting Forth, but I'm more annoyed when they spread those half-baked "truths" about Forth.
- shaftoe444 4y agoTrue, for the record I really like Forth and have had a go at implementing a forth like language interpreter (well maybe more than one go...). Getting it to be simple is not easy but it's really instructive to try.
- bowsamic 4y agoMy only gripe with Forth is that whenever I ask Forth people "what software do you build in Forth?" they say "Forths". I guess that means they are making their own specific Forth for their purposes. I tried to make some basic TODO list style app that reads and writes to a file as a basic exercise and came up against some pretty major hurdles. Specifically, managing a dynamically changing list was basically a nightmare. When I asked a group of Forth programmers why it is so difficult they just said "Forth is not suited for that problem". So I suppose Forth is not seen as a general purpose programming language by Forth fans, but then what do they use it for?
- Buffout 4y ago> "what software do you build in Forth?" they say "Forths" When you learn that Forth is a broad term that can mean a shell, programming language, application, operating system. compiler, editor, block system, style, etc..., it becomes a little clearer. Those that ask of purpose of FORTH, is same as those that ask purpose of above mentioned things.
- bowsamic 4y agoOkay but what are they doing with that? Is it just the fun of buildings tools with tools?
- Buffout 4y agoFor me it's good to know the inner details of the tool I'm using. And when I compile executable I know purpose of every byte in it. That's not possible with other languages like GO, that gives you 2MB hello world executable
- bowsamic 4y agoIt's not good to know if you never end up actually using the tool though
- 4y ago
- tristanbvk 4y agoAs a lover of assembly, I really do love the typeless nature of Forth, great fun. Along with the stack-based computation. There were also cells which was like a heap from what I recall. I taught myself some Forth, I ought to get back into it though!
- optimalsolver 4y agoA great introduction is the book Starting Forth [0]. It has the most charming illustrations I've ever seen in a text book. [0] https://www.forth.com/starting-forth/ https://www.forth.com/starting-forth/