Type opening

Lacking such concepts as "functions" and "namespaces", Mirelle makes up for them with type opening. You can make all static methods of a type globally visible with the use keyword. This can save quite a few keystrokes.

type zomg
{
  static void foo
  {
    print "hello!"
  }
}

use zomg
foo // just like zomg:foo 

It's especially useful when working with the math type:

use math
var value = abs sin 1 // instead of math:abs math:sin 1 

The type opening works only with methods. Static fields of the type will not become globally visible!

Overlapping

When two opened types have methods with equal signatures, attempt to call them will result in a compiler error, because such a call is ambigious. However, such methods may still be called by their type names.

If the globally visible method does not have parameters and an equally named variable exists in the same scope, it will be used instead of the method and no error will be ussued:

type zomg
{
  static string hello
  {
    return "hello world"
  }
}

use zomg
print hello // "hello world"

if true do
{
  var hello = "greetings, fine chaps"
  print hello // "greetings, fine chaps
}

print hello // "hello world", because the variable's scope has closed 

Last edited Mar 17, 2011 at 10:13 AM by impworks, version 3

Comments

No comments yet.