Comments on: Referencing the lib and sys
REBOL Technologies

Comments on: Referencing the lib and sys

Carl Sassenrath, CTO
REBOL Technologies
26-Sep-2010 17:56 GMT

Article #0489
Main page || Index || Prior Article [0488] || Next Article [0490] || 6 Comments || Send feedback

Ok, here's a quick tutorial on how to directly reference the runtime lib and sys from programs. (From R3 A108 and later.)

Of course, normally you don't need to do this because your scripts bind to these functions as part of the load process. However, there are times when when a lib word is overriden by a local or refinement. For instance, that happens with any and all from time to time.

To reference the function all directly, you would write:

lib/all [thing1 thing2 thing3]

Pretty easy. (That's why the default name is lib - it's short.)

Of course, if you've got that in a loop that's going to repeat a million times, the optimal method to avoid the lib lookup time is:

all': :lib/all
loop 1'000'000 [... all' [thing1 thing2] ...]

The use of ' is just a convention, and you can use whatever you want instead. Think of it as "all prime."

To reference the special functions of the sys context, first think about whether you really should be doing it at all. The sys context is "private" (non-exported) for a reason. The system object is the official place for accessible system values, not the sys context.

Ok, if you've decided it's worth the condemnation, then you would simply write something like:

print sys/boot-banner

This line is referring to the initial REBOL banner that prints on boot.

PS: Note that some sys functions are purged after boot, like load-boot-extensions and start. Keeps "really nasty" problems from happening.

6 Comments

Comments:

Maxim Olivier-Adlhoch
29-Sep-2010 8:22:44
I have a problem with the use of 'LIB as the user-context reference to the exported internals:

1) it officially makes 'LIB a reserved word. I've used 'LIB as a word in MANY different ways through the years and its a VERY useful word in general.

2) its really not clear what it means in the general view of things.

I MUCH prefer 'EXPORTS since it matches exactly what it does and its actually used in the module headers.

If you are intent on renaming it then I must suggest this much better and totally accurate term: 'RESIDENT

Part of the definition which applies directly, from random house dictionary:

-living or staying at a place in discharge of duty. -(of qualities) existing; intrinsic. -encoded and permanently available to a computer user, as a font in a printer's ROM or software on a CD-ROM. b. (of a computer program) currently active or standing by in computer memory.

other ideas, but less precise. or 'LIBRARY, 'EXPORTS, 'INBUILT, 'INHERITED

-pekr-
29-Sep-2010 8:27:31
I already expressed my opinion in the R3 Blog article regarding using integers for boot-level arguments, so I will restate that - rename of 'exports to 'lib does not sound good to my ear. Why not rename 'face, 'feel and other REBOL stuff to more traditional computing terms too? ;-) The problem with 'lib is, that it really - says nothing in particular, whereas 'exports imo much better "self-descriptory" ....
Andreas
29-Sep-2010 12:57:48
"1) it officially makes 'LIB a reserved word"

Not really. You can still use LIB in your own code, and use system/contexts/lib to refer to the lib context.

Brian Hawley
29-Sep-2010 15:26:30
I am strongly in favor of this change for two reasons:
  • Three-letter words for references that you will be making a lot. This is much better than any of the alternate suggestions above, and certainly better than system/words, let alone system/contexts/exports.
  • A clearly defined separate sys context will make most built-in utility mixin modules unnecessary - they can be added to sys instead. And it helps avoid cluttering the user word space with guru-level functions. User-level utility mixins will still be possible though.
As for the "reserved word" argument, Andreas is right, it can be overriden anytime. The only semi-reserved words will be export and hidden, at least at the top-level of a module code block.
meijeru
22-Oct-2010 5:14:44
By the way, the sys context is not protected. Thus other nasty problems can happen if the user overwrites any of the functions.
Brian Hawley
24-Oct-2010 12:04:44
Meijeru, it's worse than that: secure isn't currently working in alphas 108 and 109. We are doing a few releases to work out the kinks in the new system model and module system. Once those are settled, we will rebuild security on the new system. And finally fix those protect bugs too :)

Post a Comment:

You can post a comment here. Keep it on-topic.

Name:

Blog id:

CS-0489


Comment:


 Note: HTML tags allowed for: b i u li ol ul font p br pre tt blockquote
 
 

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 24-Oct-2017   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code