[comp.lang.forth] The Right Dictionary Structure

wsbusup@eutws1.win.tue.nl (Jan Stout) (09/26/90)

Recently having obtained a copy of FIFTH, I started to wonder about the Right
Way for Forth's dictionarystructure.
First let me explain what the FIFTHmakers concocted:

In FIFTH every word is also the name for a possible subdictionary containing
words that may ONLY be used by the word that acts as the dictionaryidentifier.
To clarify, let's draw some piece of dictionarytree:


                          : SPACES   0 ?DO SPACE LOOP ;
                              \                             
                              : SPACE    BL EMIT ;
                                  |   \
                                  \  32 CONSTANT BL
                                 CODE EMIT ... END-CODE

Imagine the current dictionary to be BL, the search order would now be:

  1 search BL's subdict. (empty in this case so:)
  2 search BL itself (ensuring that the searched for word is not BL then:)
  3 search BL's LEFT neighbours (but not their subdicts! so in this case
           only a test against EMIT would result .)
  4 search BL's parent and his left neighbours until one stumbles over FIFTH
           (the word at the root)

The idea behind all this was to eliminate the headaches of watching long
WORDSlists by listing only the subdict of a desired word.
The result of the implementation however was that when defining a word like
CR on the same level as SPACE ( : CR   13 EMIT 10 EMIT ; ), while EMIT was in
SPACEs subdict. you would have to define EMIT for CR too!
An "obvious" solution is to place EMIT in the rootdictionary, but this
is back to square 1 because the rootdictionary would grow out of control (As I
think it has in FIFTH)


I'd like to know if anyone out there who has been thinking 'bout this, 
and has come up with anything near a solution.
My own suggestion would be to let FIND search all (sub)dicts that are BELOW,
LEFT or ABOVE a given word. (in that order).
The application word then would be in one of the most LEFT subdicts.

Perhaps if someone wonders why I consider ONLY no solution is that it tends
to increase dictionarylength because the hardships required to invent a name
for every dictionary created... As every word should contain about 7 words
it should make sense to create equaly large dicts)

dwp@willett.pgh.pa.us (Doug Philips) (09/29/90)

In <67@rc6.urc.tue.nl>, wsbusup@eutws1.win.tue.nl (Jan Stout) writes:
> Recently having obtained a copy of FIFTH, I started to wonder about the Right
> Way for Forth's dictionarystructure.
> First let me explain what the FIFTHmakers concocted:
> 
> In FIFTH every word is also the name for a possible subdictionary containing
> words that may ONLY be used by the word that acts as the dictionaryidentifier.
> To clarify, let's draw some piece of dictionarytree:
> 
> 
> I'd like to know if anyone out there who has been thinking 'bout this, 
> and has come up with anything near a solution.
> My own suggestion would be to let FIND search all (sub)dicts that are BELOW,
> LEFT or ABOVE a given word. (in that order).
> The application word then would be in one of the most LEFT subdicts.

I'm curious as to what you thought about the "Libraries for Forth"
post Rob Chapman.  I thought it reminded me of Fifth, but I don't know
Fifth well enough to tell.

-Doug
---
Preferred:  dwp@willett.pgh.pa.us	Ok:  {pitt,sei,uunet}!willett!dwp

shri@ncst.ernet.in (H.Shrikumar) (10/16/90)

In article <67@rc6.urc.tue.nl> wsbusup@eutws1.win.tue.nl
  (Jan Stout) writes:
>the Right Way for Forth's dictionarystructure.
>
>In FIFTH every word is also the name for a possible subdictionary containing
>words that may ONLY be used by the word that acts as the dictionaryidentifier.
>

   This is interesting.

   Could you drop a small note on FIFTH syntax ... what constructs/syntax
does FIFTH use to specify such a tree structure ?

   In myForth I have been working on for an embedded project, I have been
using parens to do this scoping, so I'd like to see how it is here.

   I dont see the problem you mention with EMIT. Yes, words like EMIT
will have to be in the root directory. It becoming *big* per se is not
a worry, it becoming *too* *big* with words used only in one context
(context = small subset of related words in an application) is what to
watch out for.  But maybe I have not read you right.

-- shrikumar ( shri@ncst.in )