rebol - How does R3 use the Needs field of a script header? Is there any impact on namespaces? -
i'd know behaviour of r3 when processing needs field of script header , implications word binding has.
background. i'm trying port r2 scripts r3 in order learn r3. in r2 needs field of script header documentation, though made use of custom function reference scripts required make script run.
r3 appears call needs referenced scripts itself, binding seems different doing other scripts.
for example when %test-parent.r is:
rebol [ title: {test parent} needs: [%test-child.r] ] parent: ?? parent ?? child
and %test-child is:
rebol [ title: {test child} ] child: ?? child
r3 alpha (saphiron build 22-feb-2013/11:09:25) returns:
>> %test-parent.r script: "test parent" version: none date: none child: 9-may-2013/22:51:52+10:00 parent: 9-may-2013/22:51:52+10:00 ** script error: child has no value ** where: ajoin case ?? catch either either -apply- ** near: :name
i don't understand why test-parent cannot access child set %test-child.r
if remove needs field test-parent.r header , instead insert line %test-child.r there no error , script performs expected.
ah, you've run rebol 3's policy "do say, can't read mind". r3's needs
header part of module system, load needs
imported module, if isn't declared such.
loading scripts needs
quick way them treated modules in original author didn't declare them such. modules own contexts words defined. loading script module great way use script isn't tidy, leaks words shared script context. %test-child.r
script, leaks word child
script context, if didn't want happen? load needs
or import
, clean right up.
if want script treated script, use do
run it. regular scripts use (mostly) shared context, when do
script has effect on same context script called from. why child: now
statement affected child
in parent script. that's want do, why worked hard make scripts work way in r3.
if going use needs
or import
load own scripts, might make them modules , export want, this:
rebol [ type: module title: {test child} exports: [child] ] child: ?? child
as before, don't have include type: module
if going using needs
or import
anyway, in case run module do
. r3 assumes if declare module module, wrote module , depend on working way if it's called do
. @ least, declaring type
header stronger statement not declaring type
header @ all, takes precedence in conflicting "do say" situation.
look here more details how module system works: how words bound within rebol module?
Comments
Post a Comment