r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3-OLD1]

Maxim
14-Jun-2009
[15546]
the import twice crashed with a file containing only a print statement.
BrianH
14-Jun-2009
[15547x2]
There may be a pattern in the scripts you would try.,
Importing a module twice when specified with a filename instead of 
a word is almost always an error, but shouldn't crash.
Maxim
14-Jun-2009
[15549]
what do you mean "is almost always an error"?
BrianH
14-Jun-2009
[15550x3]
There is an error in the import process, but modules loaded by filename 
are actually loaded each time. If the module has a name header then 
only the first import works properly. Every subsequent import by 
filename will be a logic error. However, you can import a named module 
the first time with a filename and then use the name for all subsequent 
imports with no difficulty.


If the module is not named and specifically designed to be loaded 
multiple times, then cool, you can do so.
Naming a module enables its reuse, but all subsequent uses should 
be specified by name, not by filename.
If the module isn't already loaded then specifying it by name generates 
the filename by adding .r to the end and checking import-paths.
Maxim
14-Jun-2009
[15553x2]
ok, so far it seems strickly related to file based import... specifically, 
when it tries to load the file a second time.  it raises the assertion 
crash.


reloading a module can be needed... it was changed, for example, 
and you want to allow run-time updates, cause your ip ports must 
not be closed.
the module re-use works correctly.
BrianH
14-Jun-2009
[15555]
In theory, runtime updates should be version-triggered. The init 
code could in theory check for a prior version and migratee the data.
Maxim
14-Jun-2009
[15556]
what init code?
BrianH
14-Jun-2009
[15557]
The code in the code block of the module.
Maxim
14-Jun-2009
[15558x2]
I agree, that is the point of reloading it runtime.
but right now it crashes at the second load.
BrianH
14-Jun-2009
[15560x3]
I could use a minimal header and code block of a module that triggers 
the assertion crash on reimport by filename (bug#923).
Justt something to trace and test with.
Those assertion crashes are caused in the native code, but we need 
to narrow down *which* native code.
Maxim
14-Jun-2009
[15563x3]
I just uploaded an VERY minimal module and application with 3 imports... 
the 2 initial are by name and are fine, the third is by file and 
it crashes.
is that ok for testing?
for (bug#923)
BrianH
14-Jun-2009
[15566]
That's what I thought - it's named. You are only supposed to import 
named modules once per version - subsequent imports are to be by 
name. New versions are supposed to displace the old, and that might 
be where the crash is. This will be interesting to trace.
Maxim
14-Jun-2009
[15567x2]
have fun  ;-)
currently building example scripts for bug#924
BrianH
14-Jun-2009
[15569]
Cool, thanks.
Maxim
14-Jun-2009
[15570x2]
posted 3 file example.
re bug#924 in one test, I even had the print word not bount to any 
context !
BrianH
14-Jun-2009
[15572x2]
OK, I just looked at bug#924 and now get what you want to do. It's 
not a bug, it's by design. The code block of a module is bound before 
the block starts executing. You can't define new words in the module's 
context unless those new words are defined in imported modules or 
in the code itself at the top level, or anywhere in the code if the 
module is isolated.
Sorry, bug#928, not 924.
Maxim
14-Jun-2009
[15574]
why is that?  this means we can't create new words in a module at 
run-time?
BrianH
14-Jun-2009
[15575]
Right. Even if you did you wouldn't be able to use them because the 
code would already have been bound.
Maxim
14-Jun-2009
[15576x2]
aren't module contexts auto-expanding?
but in the script (previously global) context... every word is bound 
to the script context when loaded, why not providing the same for 
modules.  if it hasn't been set when its encountered then you raise 
the proper unset error.
BrianH
14-Jun-2009
[15578]
Not really. They are (using a hack), but the binding of the code 
block is done after the imports are processed and before the code 
block starts executing. Once the code block starts executing the 
module context has already been defined. REBOL's evaluation and binding 
rules preclude any automatic rebinding.
Maxim
14-Jun-2009
[15579x2]
but the word exists in the module before the script is done.... its 
just not set yet... so it should be bound in the module and the script 
sets the value, since its running in the context of the module.
what you are saying is that for modules, we need to start declaring 
words?  not very rebolish. 


 I have to do so in slim to keep words local to the calling context, 
 but I would have tought that modules would do so automatically since 
 they replace the global context.

 any new word in the root of the spec block of the module should be 
 added to the module's context and set to unset! just like R2's global 
 context does.
BrianH
14-Jun-2009
[15581x3]
Um, no, a DOne script is running in its own context if it is a module, 
or the current context if not. The current context is not the context 
of the calling code - it exists independently.
Modules have their own context, but they don';t replace the "global" 
context.
Any set-word in the top-level of the module's code block is added 
to the module's context before the module code runs, just like an 
object. If you isolate the module, every word in the module's code 
block and all nested blocks, parens and paths are added to the module's 
context. The only words you need to "declare" are the exported words.
Maxim
14-Jun-2009
[15584]
ok that makes sense now.
BrianH
14-Jun-2009
[15585]
The bug#928 should be dismissed, marked as "not a bug", and left 
there for future reference. Thanks for helping document R3 :)
Maxim
14-Jun-2009
[15586x4]
but its revealing something deeper... DO is now totally useless.
cause it can't interact with the context its being called from.
well, in the module's perspective anyways.
(totally is a strong word... hehe)
BrianH
14-Jun-2009
[15590]
Not totally. It is useful in non-module scripts, and useful for scripts 
done for effect rather than for loading functions.
Maxim
14-Jun-2009
[15591]
ok let me do a single little test...
BrianH
14-Jun-2009
[15592]
Also, the IMPORT function is basically a fancy DO.
Maxim
14-Jun-2009
[15593x3]
oops noticed that I mismatched the bug number in the code examples 
of bug#928... I'll edit them.
just like slim's LOAD is a fancy DO   ;-)
that would be slim's 'OPEN... starting to be late... hehe