Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

891203 Posts in 33530 Topics- by 24770 Members - Latest Member: Alexis Moroz

June 19, 2013, 07:11:02 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)choosing keyword, part 2.
Pages: [1]
Print
Author Topic: choosing keyword, part 2.  (Read 397 times)
Xecutor
Level 1
*


View Profile Email
« on: January 24, 2012, 06:42:02 AM »

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:
Code:
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:
Code:
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 Smiley
'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 Smiley
And anonymous namespace that is only available to current module.
Something like this might work:
Code:
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:
Code:
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]

Smiley
Logged
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #1 on: January 24, 2012, 08:27:33 AM »

Now I'm trying to find suitable keyword for linking symbols from some namespace to current.
In C++ when you do this:
Code:
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?

What do you feel about
Code:
namespace A{
  int x=1;
}
namespace B{
  export namespace A;

  // Alternative
  // use namespace A;     -- import it for local use only
  // expose namespace A;  -- make the namespace visible outside B, too
}
using namespace B;

The keyword export brings in namespace A into B and exposes it along with B to the client at the point of invocation, while

Code:
namespace A{
  int x=1;
}
namespace B{
  use namespace A;
  //Alternative
  //local namespace A;
  //protected namespace A;
}
using namespace B;

uses it in B but does not export it. The word "local" is self-explanatory, while "protected" (or "private", if you prefer) resembles the C++ ownership rules where members of the structure can access what's brought in, but not callers of the structure.

In fact, that seems quite natural and aesthetic:

Code:
namespace C
{
  public namespace A;
  private namespace B;
}

using namespace C;

// Here A is accessible through C, but not B
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
richardjames13
Level 0
**



View Profile Email
« Reply #2 on: January 24, 2012, 08:46:14 AM »

Code:
reveal namespace A;
show namespace A;
expose namespace A;
include namespace A;
declare namespace A;
publish namespace A;
disclose namespace A;

I'd go for expose.
Logged
Mikademus
Level 10
*****


The Magical Owl


View Profile
« Reply #3 on: January 24, 2012, 08:56:26 AM »

I'd go for expose.

Though the OP's question was which keyword to use so as NOT to expose the imported one. "expose" was my suggestion for a complimentary keyword that explicitly exports a namespace that was brought into another in an earlier directive.
Logged

\\\"There\\\'s a tendency among the press to attribute the creation of a game to a single person,\\\" says Warren Spector, creator of Thief and Deus Ex. --IGN<br />My compilation of game engines for indies
Xecutor
Level 1
*


View Profile Email
« Reply #4 on: January 24, 2012, 10:51:38 PM »

I'd go for expose.

Though the OP's question was which keyword to use so as NOT to expose the imported one. "expose" was my suggestion for a complimentary keyword that explicitly exports a namespace that was brought into another in an earlier directive.
Yes, that's correct.

Sentence 'using namespace math' doesn't look semantically complete to me. Don't know why. Probably I'm wrong.

Recent idea:
look {optinal wildcard mask} in {namespace name}

like this (assuming math is namespace):
Code:
look "*rand" in math //look for all kinds of functions that end with rand in namespace *math
or
look in math // add whole namespace math into local search

Another idea:
snoop math
Smiley
Logged
eigenbom
Level 10
*****



View Profile WWW
« Reply #5 on: January 24, 2012, 11:14:42 PM »

I like Mikademis' using namespace A local suggestion. Although the pattern matching is kinda different and cool..

And you can probably drop the namespace keyword altogether...
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic