-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does TclForth handle CREATE DOES> ? #3
Comments
Short AnswerTclForth replaces CREATE DOES> by Objecttypes. Objecttypes let you create data types as objects with private messages and methods. The objecttypes string and array make use of the native string package and associative arrays of Tcl. And that's handy for this TclForth version.
|
Long AnswerINIT
This builds the initial state at HERE. The hex number contains the (inverse) bit pattern. In TF you could create the pattern directly as a string, which handles its own buffer.
PRINT (and new INIT)
In TF this becomes 'state print'. The string is an object with a set of methods including the method print. However, this does not actually replace .state since we want to see the bitpattern as a sequence of "_" and "#". Well, then let's change the definition of state to
We don't need to bother with 0 and 1, we have string functions available for any pattern. CREATE DOES> TF uses the ObjectType mechanism to define data types. Create Does> has only one action. The Objecttype has as many actions (methods) as you want. See the definition of Variable in forth.fth.
We could create the word rules as a custom objecttype but the objecttype array already does what we need.
TclForth arrays are collections of variables (hashed, associative). In the array rules the patterns are the names and the results the values of the array variables. We can write the array in one line.
GET NEXT GENERATION:
gen replaces the state bit by bit in place instead of building the next state in a separate string or buffer. Why not use a second string for the new intermediate state.
1-DIMENSIONAL LIFE
You can't top this definition, short and to the point -- once you know how gen works. With two state strings the 1d life becomes
THE FINAL TF VERSION
|
Question
TclForth has no CREATE DOES>. How, then, would you implement this Forth example, from (http://rosettacode.org/wiki/One-dimensional_cellular_automata#Forth).
(The 'space' in .state changed to ." _")
The text was updated successfully, but these errors were encountered: