REBOL 3.0

How LOAD uses BIND and RESOLVE

Carl Sassenrath, CTO
REBOL Technologies
14-Jul-2009 17:49 GMT

Article #0220
Main page || Index || Prior Article [0219] || Next Article [0221] || 6 Comments || Send feedback

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:

 bindwith 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.
 resolvecopies 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:

  1. 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.)
  2. 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

REBOL 3.0
Updated 19-Aug-2017 - Edit - Copyright REBOL Technologies - REBOL.net