Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ah, you've run into Rebol 3's policy to "do what you say, it can't read your mind". R3's <code>Needs</code> header is part of its module system, so anything you load with <code>Needs</code> is actually imported as a module, even if it isn't declared as such.</p> <p>Loading scripts with <code>Needs</code> is a quick way to get them treated as modules even in the original author didn't declare them as such. Modules get their own contexts where their words are defined. Loading a script as a module is a great way to use a script that isn't that tidy, that leaks words into the shared script context. Like your <code>%test-child.r</code> script, it leaks the word <code>child</code> into the script context, what if you didn't want that to happen? Load it with <code>Needs</code> or <code>import</code> and that will clean that right up.</p> <p>If you want a script treated as a script, use <code>do</code> to run it. Regular scripts use a (mostly) shared context, so when you <code>do</code> a script it has effect on the same context as the script you called it from. That is why the <code>child: now</code> statement affected <code>child</code> in the parent script. Sometimes that's what you want to do, which is why we worked so hard to make scripts work that way in R3.</p> <p>If you are going to use <code>Needs</code> or <code>import</code> to load your own scripts, you might as well make them modules and export what you want, like this:</p> <pre><code>REBOL [ type: module title: {test child} exports: [child] ] child: now ?? child </code></pre> <p>As before, you don't even have to include the <code>type: module</code> if you are going to be using <code>Needs</code> or <code>import</code> anyway, but it would help just in case you run your module with <code>do</code>. R3 assumes that if you declare your module to be a module, that you wrote it to be a module and depend on it working that way even if it's called with <code>do</code>. At the least, declaring a <code>type</code> header is a stronger statement than not declaring a <code>type</code> header at all, so it takes precedence in the conflicting "do what you say" situation.</p> <p>Look here for more details about how the module system works: <a href="https://stackoverflow.com/questions/14420942/how-are-words-bound-within-a-rebol-module/14552755#14552755">How are words bound within a Rebol module?</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload