REBOL 3.0

Basic Contexts of the R3 System

Carl Sassenrath, CTO
REBOL Technologies
23-Sep-2010 18:49 GMT

Article #0334
Main page || Index || Prior Article [0333] || Next Article [0335] || 12 Comments || Send feedback

Updated: 25-Sep-2010 - Name change: "lib" replaces "exports"

With all the recent discussion about system and user contexts, module imports and exports, and the various fields of the system object, you might think that R3 has gotten complicated. It hasn't.

To understand what we mean by contexts just think of objects. An object encapsulates names (words) and their values. The contexts used in the system are essentially the same. They hold the names and values of the system as well as those of your program and any modules you've loaded. (Keep in mind that REBOL does not require object classes, so you can have a unique single object. That's what we use here.)

Here's a diagram of R3's main contexts:

The boxes are:

  • Root context - a minimal hidden context that is used by the memory manager for garbage collection.
  • System object - holds the primary references to all other values related to the system, including run-time options, catalogs, lists, objects, functions, and much more.
  • Lib context - holds all publicly exported functions (and data values too). Includes both the native and mezzanine functions of the system, as well as the exported functions and data of any modules that your program has imported. (Previously called "exports".)
  • Sys context - where private system functions are kept (as of release A108.) Some of these are used just for boot; others are special intrinsic mezzanine functions used by the system. For example, when you make a module, the module datatype creation code is a sys function, because it's called internally by the module! datatype.
  • User context - home for your program, all of its functions and data, plus any imported functions and data. (You can think of these as the "globals" of your program, although as you can see, they're not really global. They are local to your program.) If your program uses any of the values from the exports context, you will find them here as well.

The difference between system and sys should be made clear. The system object holds special values, such as settings or options, that are used by your program. The sys context is a hidden run-time library used by the R3 system and is not directly accessed by most programs.

I should also note that when you import modules into your program, each module will have it's own unique context for storing its own public and private functions and data.

To see the words of your user context, you can type:

probe words-of system/contexts/user

Or, to see the words of the lib context:

probe words-of lib

So, the system design is smart and simple. Of course, you don't need to know any of this to write programs, but if you want to dive deeper, these are the basics.

12 Comments

REBOL 3.0
Updated 26-Dec-2024 - Edit - Copyright REBOL Technologies - REBOL.net