Re: Do you currently use namespaces?

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

Yes, all the time.

But that's because I use a language where namespaces are implemented correctly, 
I think. Sorry if this is a bit long, but I don't know any way to show what I 
mean without examples.

Examples:

...File foo...

sub one
return "foo one"
;;

sub two
return "foo two"
;;

var three = 3.1

var four = [4,"foo Four"]

...File bar...

sub one
return "bar one"
;;

sub two
return "bar two"
;;

var three = 3.2

var four = [4,"bar Four"]


Using the included files:

...Main file (first method)...

use foo
use bar

println(foo.one) # must use prefix, otherwise 'undeclared symbol' err
println(foo.two)
println(bar.three)
println(bar.four)

...Results...

foo one
foo two
3.2
[4, 'bar Four']

...(second method)...

use foo (*) # import all as default
use bar

println(one) # no namespace needed, uses foo
println(foo.two) # uses foo
println(bar.three) # overrides default, uses bar
println(four)

...(third method)...

use foo (one) # only import function 'one' from foo
use bar (two,three,four) # import these funks & vars from bar

println(one)
println(two)
println(foo.two)
println(bar.three)
println(four)

...results...

foo one
bar two
foo two
3.2
[4, 'bar Four']

...(fourth method)...

use foo as a 
use bar as b            

println(a.one) # must use correct prefix for all
println(b.one)
println(a.two)
println(b.three)
println(b.four)

# println(two) # undeclared symbol err - can't accidentally get access

...(final example)...

use foo as a 
use irv.testing.bar as b 
# includes the file bar which is located in  
# my testing directory, ignoring the local bar file.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu