- Forth is the hacker's programming language.
- Coding in Forth is a little bit like writing assembly language, interactively, for a strange CPU architecture that doesn't exist.
- Forth is a virtual machine, an interpreted command-line, and a compiler all in one. And all of this is simple enough that it's easily capable of running in a few kilobytes of memory.
- If C gives you enough rope to hang yourself, Forth is a flamethrower crawling with cobras. There is no type checking, no scope, and no separation of data and code.
- Forth is about simplicity and flexibility.
- Almost nothing is included with most Forth systems by default.
- Forth is the simplest language after assembly language.
- Forth is procedural in the extreme--a Forth program is really just a chain of subroutines, called "words" in Forth jargon. There's no syntax, and all words are separated by a space and are parsed left to right. With a few exceptions for compiling, all words run right now so the Forth interpreter doesn't have to look ahead to the next word.
- The corollary of this simple setup is that Forth uses the so-called Reverse Polish Notation (RPN).
- The way that you think of as "natural" to write down math is crazy, in the sense that the look-ahead nature of the '+' operator requires either parentheses of an "order of operations" to be unambiguous.
- A computer doesn't want to know about "order" of operations", it just wants to add two numbers, preferably ones that are already sitting in ALU registers.
- New words are defined and compiled with a ':' to enter compilation mode and a ';' to exit. Compilation, such as it is, takes place immediately.
- Under the hood, the Forth interpreter is looking up each word that you use in the definition and simply stringing them together.
- All programming is about breaking complicated tasks down into reasonable-sized chunks. What constitutes "reasonable" depends a bit on the language, a bit on the programmer's own style, and a bit on the cultural zeitgeist.
- The heart and soul of Forth is the data stack, henceforth "the stack".
- Forth is a stack-based language, and until you've coded in Forth for a while, you can't appreciate what this really means and how thoughts about the stack come to dominate your coding life.
- Forth words don't take arguments or return values, instead they operate on whatever data is on the stack when they're called.
- The gimmick in Forth programming is figuring out what's needed on the stack by one word, and making sure that the word used just beforehand leaves that on the stack. In this sense, the Forth programmer defines words, but needs to think in phrases, where the contents of the stack start out empty and end that way again.
- The absolutely worst part of Forth is the stack manipulations.
- Words like swap, drop, and dup let you move items around on the stack, but too many "stack juggling" manipulations in a given word is probably a sign of bad Forth code, rather than good.
20170928
Forth: The Hacker's Language by Hackaday
Forth: The Hacker's Language
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment