A novice package

Novice Package by Hugh Aguilar

with grateful to Hugh Aguilar and SVFIG !

Novice Forth


I have written some ANS-Forth code that I have put in the public-domain (BSD license) as a contribution to the Forth community. Most people who get interested in Forth will write a Forth compiler as an exercise in assembly-language, but they never write any applications in Forth. By comparison, my novice package is oriented toward writing applications. I also provide some small to medium-sized example applications to prove to the novice that writing non-trivial programs in Forth is possible. The novice may wish to upgrade these demos as an exercise, or at least study them to see how applications are written.

The novice package includes the following (and more):

NOVICE.4TH --- This file is required by most of the other files. Here we have simple data structures such as records and arrays. I have fixed a lot of problems in ANS-Forth, such as there being no way to determine if a memory block came from ALLOCATE or ALLOT, or what the size of the memory block is. I have dispensed with CREATE DOES> altogether, and use :NAME instead. This is another example of fixing a problem in ANS-Forth --- making :NAME available is the primary purpose of my releasing this software.

LIST.4TH --- This file contains a linked-list data-structure. Lists can be used in much the same was as sequences are used in Factor. This file also contains lists of strings (SEQ lists) and comma-delimited strings (DECOMMA lists) that are useful in many applications. All in all, the list code is the most practical of all the code that I have written. My slide-rule program is a good example of using lists as the basic data-structure for the entire program.

ASSOCIATION.4TH --- This file contains code for associative arrays. It uses Left-Leaning Red-Black (LLRB) trees internally. In addition to FIND-KEY, INSERT and DELETE, I also have code for extracting nodes inside or outside of a range. I prefer lists, but a lot of people (Awk and Lua programmers, for example), use associative arrays as their primary data-structure. This is not a bad way to program, and my code will help you do so in Forth.

CF.4TH --- This file contains Nathaniel Grosman's continued-fraction program (Long Divisors and Short Fractions (Forth Dimensions Sept/Oct 1984)). The purpose of this program is to calculate rational approximations for use by */ or M*/ to multiply that rational by an input parameter. This is the only major example of code included in the novice package that I didn't write myself.

RATIO.4TH --- This file contains code based on LIST.4TH supporting lists of rational numbers. These can provide better accuracy than floating-point numbers for repeating decimals.

QUEENS.4TH --- This file contains code to solve the famous N-Queens problem. I use a non-recursive backtracking algorithm of my own design. This is the only non-trivial program I have in the package that is *not* recursive, which is somewhat ironic as the N-Queens problem is typically given to novices as a classic example of recursion.

SYMTAB.4TH --- This file contains a symbol table. The algorithm is my own invention. If you have a lot of memory (modern desktop computers do), then a hash table is a better choice. Given limited memory, such as for an MS-DOS computer (one 64K segment for the headers), then symtab is the best choice. Symtab assumes that there is a lot of variance in how often the nodes are accessed, which is typical for a symbol table. If all the nodes are roughly equal in popularity, which is typical for an associative array, then ASSOCIATION.4TH would be a better choice.


LowDrawStrategies.4th --- These files do an analysis of low-draw poker using a recursive-descent search. This is not a Monte-Carlo "analysis," but it is a *complete* analysis of the probabilities. This software also allows the user to set up customized situations and obtain the probabilities for the various options (fold or call). This is useful for when you wake up the next morning with a loser's hangover, and you want to prove to yourself that you chose the *correct* option --- even though you lost the hand and all of your money.

All of the source-code files have associated text files (same name with a .TXT extension) that provide documentation. I also have a file NOVICE.PDF that discusses the novice code. This is a short file that only discusses a few of the more important aspects of the code. It is written for advanced programmers who are deciding if they want to recommend my novice package to novices or not. I can be contacted at hughaguilar96 -at- yahoo.com for comment. If you have any software that you would like included in the novice package, I would be willing to do this if I think that it is a good example of using the novice package and/or would be useful for novices to learn from. I would give you credit for writing the code.

Hugh Aguilar

hughaguilar96 -at- yahoo.com

novice.forth.zip - 239 Kb zip file this file is up to date to Oct.2020

original document : -- http://www.forth.org/novice.html --