💾 Archived View for thrig.me › tech › forth › starting-forth.gmi captured on 2023-11-04 at 12:46:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-04-19)

-=-=-=-=-=-=-

Starting Forth

Perhaps the best way to learn Forth is to work through the book "Starting Forth" by Leo Brodie, a PDF of which can be found in numerous places on the Internet. There is also "Thinking Forth" but that text it more about how to think about programming than getting down to brass tacks with a forth.

Starting-FORTH.pdf.gz

This book is not without problems though has held up quite well for a technology book from 1981; for one, the ANS specification specifies the .S word; "Starting Forth" predates ANS and derives .S from scratch.

15.6.1.0220 .S dot-s TOOLS ( -- )
Copy and display the values currently on the data stack. The format of the display is implementation-dependent.

More troubling especially to a beginner is that "Starting Forth" assumes a particular cell size that may not match what modern forth implementations on modern systems use. In particular old Forth assumes a 16-bit cell size; a modern Forth such as gforth or pforth on a 64-bit system probably uses 64-bit cells. This means that memory address calculations will be off. ANS now specifies CELLS to obtain the size of N cells:

6.1.0890 CELLS CORE ( n1 -- n2 )
n2 is the size in address units of n1 cells.

The difference can be seen between pforth and eforth (the cli tool for eforth is embed, but I renamed it to eforth) where 1 or 2 cells is 8 and 16 in pforth (64-bit) but only 2 and 4 in eforth (16-bit).

	$ pforth
	1 cells    ok
	2 cells    ok
	.s Stack<10> 8 16
	   ok
	bye
	$ eforth
	eFORTH v1984
	 5414 10970
	1 cells
	 ok
	2 cells
	 ok
	.s
	 2 4 <sp
	 ok
	bye

What this means is that when "Starting Forth" asks you to "6 ALLOT" to allocate six cells, in a modern forth you will probably need to "6 CELLS ALLOT", or "72 CHARS ALLOT" when you want characters, etc.