wmb@MITCH.ENG.SUN.COM (08/28/90)
> BTW, what's this ENVIRONMENT? thing which takes a string argument? > I'm reluctant to comment until I see its ANS definition, but it sure > seems like someone is taking immense pains to do things the hard way. > (Isn't parsing strings what we have a dictionary for?) ENVIRONMENT? maps a string into a value. Its stack diagram (working from memory) is: ENVIRONMENT? ( adr len -- false | n true ) If an environment description entry matching the string "adr len" is present, returns true and the value of that entry. Otherwise returns false. There are 2 reasons why this mechanism is separate from the normal dictionary lookup mechanism: 1) The number of environment description entries is potentially large, and many people deemed it unacceptable to waste dictionary space for words which are likely to be used either 0 or 1 times in a typical application. By providing a special word, the potential exists for storing those environment descriptions somewhere else, like in a disk file or in a block. They could be in the dictionary, but they don't have to be there. 2) If they are in the dictionary, that pretty much implies the existence of a search order mechanism, which is currently an optional extension. The committee did not want to require search order in terms of environment. Note that ENVIRONMENT? is a required word. However, a minimal system may choose to save space by implementing it as 2DROP 0 , thus indicating "I don't know" for every environment query. A portable application is expected to check for the "I don't know" condition after every use of ENVIRONMENT? , supplying a default value in that case. It turns out that the Forth-based firmware on Sun products uses a similar scheme for reporting system configuration information to Unix. The existence of the "I don't know" case is absolutely essential, because it allows us to add new named properties at will, yet the new version of Unix will still work with old firmware that doesn't implement the new property. This feature has allowed me to say "no problem" to difficult questions more times than I can count. My experience with this scheme has been overwhelmingly positive. The Unix guys love it (which makes them feel good about the Forth PROMs!). Mitch