# Word tables

The /lib/wordtbl.fs unit allows the creation of word tables allowing those words
to be called by their index. Example:

    3 wordtbl mytbl
    :w 42 . ;
    'w anotherword
    :w 54 . ;

    mytbl 2 wexec \ prints 54
    : foo mytbl 1 wexec, ;
    foo \ calls "anotherword"

Its structure is a first cell containing the table's length (in number of
elements) followed by that many cells, containing a pointer to a word.

## API

Words:

wordtbl ( n "tbl" -- a )
  Create a new table named "tbl" with "n" entries in it, allocate enough space
  for these entries and yield its address. Following this creation, exactly "n"
  words must be added to the table with ":w" or "'w".

wordrefs ( n "tbl" -- )
  If all you have are references to existing words (that is, that you're only
  going to use "'w"), this word saves you some typing:

    3 wordrefs foo bar baz
    3 wordtbl 'w foo 'w bar 'w baz

  are the same thing.

:w ( a -- a+4? )
  Define a word like ":" would, but anonymously (no name). Also, write the
  address of the newly defined word to "a". If there is still free space in the
  wordtbl, return "a+4", otherwise return nothing. The idea is that after all
  entries for a table are created, PS doesn't contain "a".

'w ( a "name" -- a+4? )
  Find "name" in system dict and write its reference to current wordtbl in the
  same way ":w" does.

wtbl@ ( tbl idx -- w )
  Return address of word at index "idx" in "tbl". Aborts if idx is out of
  bounds.

wexec ( tbl idx -- )
  Execute word at index "idx" in "tbl". Aborts if idx is out of bounds.

wexec, ( tbl idx -- )
  Compile execution of word at index "idx" in "tbl". Aborts if idx is out of
  bounds.

wordtbllen ( tbl -- len )
  Yields the number of elements in "tbl".
