I'm still working on my dynamically typed programming language, and made some serious progress recently. One of features I've added is support for namespaces.
Like this:
namespace ns1
x=1
end
print(ns1::x)
namespace ns1::ns2
x=2
end
print(ns1::ns2::x)
Now I'm trying to find suitable keyword for linking symbols from some namespace to current.
In C++ when you do this:
namespace A{
int x=1;
}
namespace B{
using namespace A;
}
using namespace B;
all symbols from B
and A are injected into global symbols table.
That's what I want to avoid.
What is the best keyword for importing/using/linking multiple/all symbols from specified namespace to current?
'import' is almost fine. But semantically symbols are not imported into current namespace. It's that namespace is added to search.
'using' IMO is stupid keyword

'link' and 'connect' are probably bad choice as keywords. In my language cannot any have identifiers that are reserved as keywords.
Hm. I have 'alias' keyword, that creates ... alias for another symbol

And anonymous namespace that is only available to current module.
Something like this might work:
namespace ns1
x=1
end
namespace
alias *=ns1::*
end
But looks somewhat cumbersome.
Ideas, suggestions?
Here comes big post scriptum.
Today following code started to work:
attr rarity
class Item(level)
level
end
class Bonus
end
class IntBonus(value):Bonus
value
func describe()
return "intellegence +$value"
end
end
class StrBonus(value):Bonus
value
func describe()
return "strength +$value"
end
end
class Sword(l):Item(l)
@{rarity=70}
power=10+level*5
func describe()
return "Sword +$power"
end
end
class Shield(l):Item(l)
@{rarity=50}
defense=10+level*5
func describe()
return "Shield [$defense]"
end
end
class Ring(l):Item(l)
@{rarity=20}
bonus=(a=Bonus.getChildren())[math::irand(#a)](3+math::irand(level))
func describe()
return "Ring of $bonus.describe()"
end
end
func spawnItem(level)
sum=0
items=Item.getChildren()
for i in items
sum+=i.{rarity}
end
sum=math::rand(sum)
for i in items
r=i.{rarity}
return i(level) if sum<r
sum-=r
end
end
for i in 1..10
print(spawnItem(3+math::irand(3)).describe())
end
output:
Shield [25]
Ring of strength +6
Sword +35
Shield [35]
Ring of intellegence +3
Sword +35
Sword +25
Sword +30
Shield [35]
Shield [30]
