Author: Ian Osgood
Date: 10:07:40 09/20/01
Go up one level in this thread
On September 20, 2001 at 05:32:06, Dan Andersson wrote:
>You get both data structures and do have local variables (even if you do not
>need them due to the data stack, really!). There is even a slew of object
>oriented packages, each suted to different needs. Our friend Ian does not seem
>to have studied the language enough time.
Admittedly, I have only been looking at Forth and sample programs for a few
days. I've been trying to find Forth resources on the web. Especially articles
along the lines of "Forth for C programmers" or "Common idioms for Forth."
The chess program mentioned above was originally written for a Forth variant on
a Spectrum Z80-based computer in the 80's. The Forth chip developers then
adapted it for their chips (with a graphic board display to the built-in video
signal generator), and finally made a text-mode version suitable for standard
ANS Forth compliant systems. So I imagine its design only assumes the least
common denominator of all the Forth variants.
The chess program does use structures in a way... it has an abstraction of a
stack of boards + local variables (equivalent to a C search function stack
frame). Instead of a typedef'ed struct describing this, it uses a set of
"words" to access data at particular offsets from the base address of one of
these boards. In C: instead of stackItem->field1, it would be referenced:
int &field1(stackItem *p) { return *((int *)p + kField1Offset); }
where there is a function for each possible field in the structure. (Actually,
this is how the program supports seperate local variables for each level of
search recursion. It uses a custom stack instead of the parameter or call
stack. A design like this also helps with the limited size of the call stack on
the Forth chip.)
Are more convenient ways to specify structures and named local variables in
modern Forth variants?
Ian
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.