Skip to content

v2.0.0-alpha11

Pre-release
Pre-release
Compare
Choose a tag to compare
@pachanga pachanga released this 05 May 15:24
· 1845 commits to master since this release
  • Adding initial namespaces support which led to major internal type system overhaul
  • Namespace symbol aliases not available yet

Conceptually namespaces are quite similar to the implementation found in C#: one is free to declare and nest namespaces anywhere in the code. It's possible to span namespaces across multiple files.

File: std/io.bhl

namespace std {
namespace io {
  func int WriteLine(string line) {
    …
  }
}
}

File: main.bhl

import "std/io"

func main() {
  std.io.WriteLine("Hello World!")
}

In case you need to explicitly lookup a symbol in the global namespace you have to prefix it with . (dot), for example:

namespace foo {
   func yield() {
     …
   }

   func test() {
      yield()  // will lookup foo.yield()
      .yield() // will lookup built-in global yield()
   }
}