How LOAD uses BIND and RESOLVE
If you look at load in R3 A71, you will notice these two lines:
bind/new data system/contexts/user
resolve system/contexts/user system/contexts/exports
To summarize, here's what's happening:
| bind | with the /new refinement scans data (the block being loaded) and extends the system/contexts/user (SCU) with any new words that are found (not just set-words, all words.) It also binds those words to SCU.
|
| resolve | copies the values for all words in SCU that also appear in SCE. In other words, it is "importing" their definitions from the master export list into your program context. The export list contains on only system values, but all exported module values (e.g. if you loaded a math module earlier).
|
These actions take place in load rather than in do for a couple reasons:
- We do not know the intended use of any word. It may be evaluated, or it may not (e.g. could be in a list of variables.)
- By resolving in load, we don't slow down do, which we want to keep fast.
You can think of this process to be like that of a loading linker that is used in other languages. Most of the time it should be invisible, and you don't really need to think about it.
It should also be mentioned that modules themselves use a similar method, but rather than binding to SCU, they bind to their own private contexts.
Update notice:
In A75 the intern function has been added to combine bind and resolve in a common way. It also solves the problem mentioned by Grabriele below.
6 Comments
|