REBOL 3.0

Isolated namespaces in modules

Carl Sassenrath, CTO
REBOL Technologies
24-Mar-2009 0:24 GMT

Article #0179
Main page || Index || Prior Article [0178] || Next Article [0180] || 6 Comments || Send feedback

Note: The comments section here contains substantial additions and insights on this topic.

R38 will be making some changes to the definition of modules. One change is that a module, when imported, will by default bind with the system exports for its external functions.

Stated another way, modules do not create full namespaces for all words. They will share system words. Reason: most modules work fine sharing the system definitions (especially if we add a locking mechanism to prevent changes.)

The change is simpler than it sounds. Take the module source:

save %mod-test.r [
    REBOL [
        type: module
        exports: [test]
    ]
    test: func [a] [print a]
]

Now, import it normally:

m: import %mod-test.r
probe words-of m
[test]
test 123
123

But, if you import with the /isolate refinement, the module's global context will be isolated (but it will still be be resolved with the system export context):

m: import/isolate %mod-test.r
probe words-of m
[test func a print]
test 123
123

So, it works exactly the same. The refinement is only useful for cases where you want to redefine one or more global functions, but only within the context of the module (not for the entire system). So, that's why it is no longer the default.

6 Comments

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