Archive: forth/lists

Up to parent directory

ChangeLog 25Oct09 08:43:50EDT 3.4K
NOTATION 30Nov04 13:25:05EST 845 Source conventions.
list-words.txt 02Sep06 12:46:20EDT 2.8K A functional listing of words in the four kinds of list.
nodespace.fs 20Oct10 15:33:17EDT 7.7K Allocation and deallocation of nodes, including "unused" chain.
nodespace-pfe.fs 31Aug06 23:08:58EDT 2.6K Extension of the above for dynamic-string node initialization.
sendlist.fs 01Sep06 13:01:41EDT 3.7K Definitions common to single-ended lists.
dendlist.fs 01Sep06 13:07:32EDT 4.1K Definitions common to double-ended lists.
snode.fs 20Oct10 15:31:10EDT 1.8K Single-linked node structure.
dnode.fs 01Sep06 13:20:07EDT 2.0K Double-linked node structure.
sslist.fs 31Aug06 23:04:02EDT 3.6K Single-ended, single-linked lists.
sdlist.fs 31Aug06 23:03:46EDT 5.1K Single-ended, double-linked lists.
dslist.fs 31Aug06 23:03:31EDT 5.2K Double-ended, single-linked lists.
ddlist.fs 31Aug06 23:03:17EDT 8.1K Double-ended, double-linked lists.
sexample.fs 30Nov04 13:25:26EST 3.3K Single-linked examples.
dexample.fs 30Nov04 13:24:39EST 4.5K Double-linked examples.
undef.fs 30Nov04 13:37:26EST 729 A bootstrap for [UNDEFINED].

Up to top of archive

Files in this directory under the GNU LGPL typically have a POLITENESS request.
This page was last updated by DNW on September 5, 2006.

List Library Overview

These files provide a library which implements four kinds of lists in Forth, with essentially all ANS compatible code. There is a system-dependence on the nonoccurrence of zero node addresses.

The organization of this overview is adapted from the comments in the BSD Unix sys/queue.h header file. Our terminology is slightly different: single-ended and double-ended, single-linked and double-linked lists instead of singly-linked lists, lists, simple queues, and tail queues. The code was written without referring to any C approach.

Heads and tails in list structures hold the addresses of the first and last nodes in the list.

As usual, all insert and remove operations can be done in principle with any of the list types; but not all are natural. We do not implement unnatural operations, those that require list traversal.

  1. Single-ended, single-linked lists. List structures have a head but no tail, so nodes may be prepended to the list, and the first node may be removed.

    Nodes have only forward pointers, so the natural traversal is forward, and nodes may be inserted or removed after any node.

  2. Double-ended, single-linked lists. List structures have both a head and a tail, so nodes may be prepended or appended to the list, and the first and last nodes may be removed.

    Nodes have only forward pointers, so the natural traversal is forward, and nodes may be inserted or removed after any node.

  3. Single-ended, double-linked lists. List structures have only a head, so nodes may be prepended to the list, and the first node may be removed.

    Nodes have both forward and backward pointers, so both traversals are natural, and nodes may be inserted or removed before or after any node.

  4. Double-ended, double-linked lists. List structures have both a head and a tail, so nodes may be prepended or appended to the list, and the first and last nodes may be removed.

    Nodes have both forward and backward pointers, so both traversals are natural, and nodes may be inserted or removed before or after any node.

It would be easy to add circular variants as well.

Loading

The Forth source files in this distribution use the common practise but nonstandard word REQUIRED to load external files. All the .fs files listed above need to be placed in a directory where the host system can find them via REQUIRED.

These files are intended to be loaded by the application as a library. To facilitate that, each of the main files for the four types of list, sslist.fs, dslist.fs, sdlist.fs, and ddlist.fs, loads any of the other .fs files it needs, plus the files that complete the application glossary for the corresponding list type.

Any subset of the four may be loaded together without conflict.

The file nodespace-pfe.fs also uses the nonstandard, pfe word LOADM to load the dstrings shared library module, which implements our Dynamic-Strings word set. It becomes ANS Forth compatible if dstrings.fs is loaded instead.

Uncommenting

Some of these files contain words commented out with
  0 [IF] ... [THEN]
They are flagged as "uncommentable" in list-words.txt and in the files themselves. The intent is not that they should actually be uncommented in the list library files themselves, but that they should be pasted into the application as needed, and customized there.

Some word definitions have alternate versions with or without locals commented out with "\". Here the intent is for information only.

All code hidden in either kind of comment has been tested at the same level as the rest of the code. Bug reports for "normal" and "commented-out" code are equally welcome.