whartung wrote:
There's a lot of unfamiliarity going on, so, especially early on, the cognitive load per character is really high.
Yes, Forth has a brutal learning curve. I spent the first weeks yelling
What?! at the screen so much I felt like the Tenth Doctor. Some things that helped me:
Swallow your pride and put a stack comment after every single word, at least at the beginning. You'll feel stupid, yes, but you can walk through the code step-by-step. Once you know the code works, you can go back and condense the comments. But don't. You'll thank yourself when you come back in a year.
Use a modern Forth. Old Forths try to do all kinds of stuff at once - exhibit A is
FIND which returns
( addr 0 | xt 1 | xt -1 ) depending if it found the word, and if the word is immediate, and I can never remember what
addr is. ANSI Forth (and Gforth, which seems to have become the real standard) follow the philosophy of doing
one thing:
FIND-NAME is
( addr u -- nt | 0 ) (or xt instead of nt, depending on your Forth).
REFILL just returns a flag if it worked or not.
PARSE-NAME replaces
WORD and just does
( "name" -- addr u ) while
WORD ends up being
BL WORD COUNT anyway and then does something weird with an extra space character at the end of the input.
Write shorter words. This is still one of my biggest problems, my words still tend to be multi-line. It seems wasteful, but remember that a good Forth compiler will turn everything into very small assembler snippets.
Rewrite again and again. I mostly use Python, where there is supposed to be one obvious way of doing things, and there usually is. Forth rewards going back over your code and refractoring it. That is where you'll have sudden insights about how
CREATE DOES> would be really cool or how you really should use
DEFER (I love
DEFER). This means that your Forth code will follow Hemingway's famous line about normal writing: "The first draft of everything is ****."
I know what you mean about not knowing what the words are for. It took me ages to realize that
COUNT is also used to walk through strings, not only to convert old style to new style. Maybe somebody should start a "bestiary" of Forth words with examples and such?