forked from munificent/magpie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespaces.mag
37 lines (29 loc) · 1006 Bytes
/
namespaces.mag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// A namespace expression specifies a name and a body. Within the body, all new
// variables or members that aren't fully-qualified will be qualified with the
// name of the namespace:
namespace foo
var bar = "123" // Declares a variable "foo.bar"
class Blah // Declares a class "foo.Blah"
def method() // Declares a method "foo.method"
end
def func() nothing // Declares a function "foo.func"
var other.bar // Declares a variable "other.bar"
end
// A using specifies a name. Within the current scope, the name is added to
// the list of available namespaces. Any unqualified name within that scope will
// be looked up in that namespace before trying other namespaces:
namespace first
var foo = "first.foo"
var bar = "first.bar"
end
namespace second
var foo = "second.foo"
end
do
using first
print(foo) // "first.foo"
print(bar) // "first.bar"
using second
print(foo) // "second.foo"
print(bar) // "second.bar"
end