Re: Namespaces

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

irv mullins wrote:
> 
> 
> I have a global function foo() declared in two includes:
> 
> include inc1.e
> include inc2.e as two
> 
> ? foo()
> 
> I get an error:
> 
> test.exu:4
> A namespace qualifier is needed to resolve foo.
> foo is defined as a global symbol in:
>     inc1.e
>     inc2.e
> 
> Why is this? 

Because in the statement '? foo()', the interpreter does not know 
which of the two foo() functions you wish to invoke. Because it can see
two functions both named the same, and you haven't explictly identified
which of them to run, it sees this as ambiguous.


>Logically, there should now be two functions visible to 
> my main program (test.exu), one named two:foo()
> and another function named just foo().

The first part is right, there are two foo() functions visible. But they
are both *called* 'foo'. The namespace qualifier is NOT a part of the
function's name. It is only used by the interpreter to disambiguate 
an identifier at the point of reference.
 
> Obviously, I know how to "fix" it - just add a namespace to inc1.e also, 
> and then go thru my code and add that namespace to all references to foo().
> 
> But why is that necessary?

Because! Just kidding ... 

Yes it would be nice if an unqualified reference to a global variable 
meant that the interpreter would just look in the 'unnamed' global 
namespace. But I'm sure that would just cause other headaches too.

-- 
Derek Parnell
Melbourne, Australia

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

Search



Quick Links

User menu

Not signed in.

Misc Menu