1. [phix] How does namespacing work?

Test one

namespace m 
include builtins/map.e 
 
map x = new() 
put( x, "one",  1000 ) 
? get(x, "one" ) 
 
/* 

? get(x, "one" ) 
  ^ a namespace qualifier is required 
get is defined in: 
    /usr/local/bin/builtins/map.e, 
    /usr/local/bin/builtins/get.e. 
*/ 

Test two

namespace m 
include builtins/map.e 
 
map x = new() 
put( x, "one",  1000 ) 
? m:get(x, "one" ) 
 
/* 

? m:get(x, "one" ) 
    ^ undefined identifier get 
*/ 

_tom

new topic     » topic index » view message » categorize

2. Re: [phix] How does namespacing work?

_tom said...
namespace m 
include builtins/map.e 
 
map x = new() 
put( x, "one",  1000 ) 
? m:get(x, "one" ) 
 
/* 

? m:get(x, "one" ) 
    ^ undefined identifier get 
*/ 

map.e defines its own namespace, "map."

I wonder if map.e didn't define its own namespace, would adopt "m" as its namespace. Certainly not! That would not be expected behavior... would it?

namespace m 
include builtins/map.e 
 
map x = new() 
put( x, "one",  1000 ) 
? map:get(x, "one" ) 
new topic     » goto parent     » topic index » view message » categorize

3. Re: [phix] How does namespacing work?

"map" is not the default namespace of builtins/map.e

include builtins/map.e  
  
map x = new()  
put( x, "one",  1000 )  
? map:get(x, "one" )  
 
/* 

? map:get(x, "one" )  
     ^ '(' expected 
*/ 

_tom

new topic     » goto parent     » topic index » view message » categorize

4. Re: [phix] How does namespacing work?

_tom said...

"map" is not the default namespace of builtins/map.e

Oops. I was thinking Euphoria.

Pete, why no namespace for maps?! smile

new topic     » goto parent     » topic index » view message » categorize

5. Re: [phix] How does namespacing work?

Phix is not very good at overloading. Currently when it sees "map", it thinks "oh good, the type map", if we added "namespace map" then it would think "oh good, the namespace map, now where's the colon?" (and barf on the "map x = new()"). It is the overloading, trying to use "map" for two different things, that it struggles with. However, this works fine:

include builtins/map.e as m 
   
map x = new()   
put( x, "one",  1000 )   
? m:get(x, "one" )   

Of course instead of "as m" you could put "namespace m" inside/at the start of map.e.

This is clearly fixable, as you could deduce from the [absence of a] trailing ":" whether a namespace or something else was intended, not that I have any immediate plans or any idea how long it might take, plus:

Two or three years ago I took the decision to prohibit builtin overrides in Phix, which is another form of overloading: it caused several problems which were just too difficult to fix, and I have never looked back from that decision.

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu