1. Namespace

Hello Everybody,

Namespace, What is it? What is it used for? Where can I see examples? Where is it documented?

Don Cole

new topic     » topic index » view message » categorize

2. Re: Namespace

Hello Don,..

Selgor here..

I googled "namespace in euphoria" ...

Result was enlightening..

Many interesting topics..

At the bottom it mentions Phix..

But, a lot of reading..

C seems to use it and defines it ...

Well, maybe you read it ...

And this sight below must be ""historic""..

www.juliepetrusa.com/Euphoria.htm .......

Hope this does not cause you more "pain"..

Cheers. Selgor.

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

3. Re: Namespace

dcole said...

Hello Everybody,

Namespace, What is it? What is it used for? Where can I see examples? Where is it documented?

The namespace concept was created to get around a common problem with Eu v3.

When two independently created libraries both expose the same symbol name, how does your program, when it includes both libraries, know which name you are referring to in your code?

For example...

-- LIBRARY A -- 
global integer theXvalue = 'x' 

-- LIBRARY B -- 
global sequence theXvalue = "X" 

--- Your App ---- 
include lib_A.e 
include lib_B.e 
 
theXvalue = someFunc() 

The problem is, when your code runs, it doesn't know which theXvalue you want to set. Is it the one in Library A or Library B?

In this situation you can use namespaces to help you tell Euphoria which to use.

--- Your App ---- 
include lib_A.e as libA 
include lib_B.e as libB 
 
libA:theXvalue = someFunc() 
if find(libB:theXvalue, libA:theXvalue) then ... 

As you can see, you can explicitly disambiguate your code by telling Euphoria which exposed symbol you need to use.

It is documented in section "4.8.1 include" of the documentation.

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

4. Re: Namespace

Read this (RDS Eu 4.0 docs): http://oe.cowgar.com/docs/eu400_0014.html#_114_usingnamespaces

Pete

(still working on your other problem, btw)

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

5. Re: Namespace

Thank you Signor and Derek,

Signor: I read all of it. Manual 1 Section 2 was especially enlightening.

Derek: I guess it's the as that makes it a namespace. It's in "4.8.1 include" of what document?

Don Cole

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

6. Re: Namespace

dcole said...

Thank you Signor and Derek,

Signor: I read all of it. Manual 1 Section 2 was especially enlightening.

Derek: I guess it's the as that makes it a namespace. It's in "4.8.1 include" of what document?

Don Cole

The manual. It is this link: http://oe.cowgar.com/docs/eu400_0020.html#_144_include

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

7. Re: Namespace

Namespaces also gives you data encapsulation.

A Euphoria program could start like this:

include sets_simple.e as person_set 
include sets_simple.e as inventory_set 
include sets_binary.e as receipt_set 

If you always use the namespaces, you can shift from one implementation to another simply by changing the included filenames named in the file. This works as long as the identifiers are present in all of the implementations and implement the same thing.

Shawn

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

8. Re: Namespace

SPringle said...

Namespaces also gives you data encapsulation.

I'm afraid not. It doesn't work that way at all. It only disambiguates symbol names and has no effect at all on data storage.

SPringle said...

A Euphoria program could start like this:

include sets_simple.e as person_set 
include sets_simple.e as inventory_set 
include sets_binary.e as receipt_set 

If you always use the namespaces, you can shift from one implementation to another simply by changing the included filenames named in the file. This works as long as the identifiers are present in all of the implementations and implement the same thing.

In the situation above, only a single copy of the variables declared in sets_simple.e would have RAM reserved for them. Meaning that even though one can include a file many times, only the first time actually reserves space for its contents. Subsequent includes for the same file (with different namespace IDs) just create aliases for the exposed symbols without reserving further space.

For example, if the file simple_sets.e had the symbol global integer status defined then the following code was executed ...

person_set:status = 1 
inventory_set:status = 2 
writefln("Status: Person = [], Inventory = []", {person_set:status, inventory_set:status}) 

The output would be ...

Status: Person = 2, Inventory = 2 

Because there is only one status field created in RAM but it has two names now.

It is expected that some release after V4.1 will implement something along the lines that you have mentioned.

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

9. Re: Namespace

The problem you outlined will simply not be if the modules consist of routines that only use what you pass into them, such as using new() and is_match() from wildcard or from regex.

Shawn Pringle

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

Search



Quick Links

User menu

Not signed in.

Misc Menu