Re: Problem with Euphoria namespace-mechanism

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
From: <tommy.carlier at pandora.be>
To: "EUforum" <EUforum at topica.com>
Subject: Problem with Euphoria namespace-mechanism


> 
> 
> I have a little problem with the namespace-mechanism.
> 
> I've created a library to read and write a specific file-format. For easy 
> maintenance I've split this library in different files (reader.e, parser.e, 
> writer.e, ...). I've also created a generic library-file (smel.e) that only 
> contains include-statements to the different files. Now when I use this 
> library in a program, I use the include statement "include smel.e as smel". 
> But when I try to call a procedure/function using the namespace (example: 
> "smel:ReadDocument()"), the procedure/function cannot be found. If I don't 
> use the namespace, the thing works like it should.
> 
> Schematic:
> 
>                include              include
>    PROGRAM.EX  ------->  LIBRARY.E  ------->  LIB_01.E, LIB_02.E, LIB_03.E
> 
> ------------------
> -- PROGRAM.EX
> 
> include library.e as lib
> 
> lib:global_procedure_from_lib_01() -- doesn't work
> global_procedure_from_lib_01() -- does work
> 
> ------------------
> -- LIBRARY.E
> 
> include LIB_01.E
> include LIB_02.E
> include LIB_03.E
> ------------------

Ok, I can see the issue.

The 'lib' namespace on the library.e include means that the globals DEFINED IN
library.e can be used with the 'lib:' prefix. Any global ids defined inside the
files that are included in library.e are NOT subject to the 'lib' namespace. In
other words, namespaces only go down one level of include. Also namespace only
apply to the file that its defined in. So this code below wouldn't help either
...

 -- LIBRARY.E
 
 include LIB_01.E as lib1
 include LIB_02.E as lib2
 include LIB_03.E as lib3
------------------

 include library.e
 
 lib1:global_procedure_from_lib_01() -- undefined namespace
 global_procedure_from_lib_01() -- still works

------------

Only use namespaces if you are forced into resolving ambiguous references. In
your case here, you are not being forced because the routine names are not
ambiguous so you shouldn't bother with them.

If later, you include library.e and somebody else's library that has a clashing
name, then you will be forced to do something like this (assuming the clash was
with a procXXX in lib_02.e) ...

 -- LIBRARY.E
 
 include LIB_01.E
 include LIB_02.E
 include LIB_03.E
------------------

 include library.e
 include foreign.e as fgn
 include LIB_02.e as lib2
 
 lib2:procXXX()
 fgn:procXXX()

----------
Note how you have to 'reinclude' LIB_02.e even though it was already included
inside library.e.

The situation you are using is very similar to the win32lib.e library, which
includes a number of smaller libraries. People who use win32lib currently do not
have to be concerned about exactly which of the smaller libraries the ID they
need is defined in, until they have a clash. Fortunately the error message now
tells you where the names are defined and you can reinclude the specific file
with a namespace qualifier to remove the clash.

Hope this helps.
-- 
Derek

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu