15 lines
842 B
Plaintext
15 lines
842 B
Plaintext
var v; // global to the class that encloses this file
|
|
class C{ var v } // global to class C, each instance gets a new v
|
|
class C{fcn f{var v=123;}} // v can only be seen by f, initialized when C is
|
|
class C{fcn init{var [const] v=5;}} // init is part of the constructor,
|
|
so vars are promoted yo class scope. This allows const vars to be created at
|
|
construction time
|
|
var v=123; v="hoho"; //not typed
|
|
class C{var v} // C.v OK, but just v is not found
|
|
class C{var[const]v=4} // C.v=3 illegal (compile or run time, depending)
|
|
class C{var[mixin]v=4} // the compiler treats v as an int for type checking
|
|
class C{var[proxy]v=f; fcn f{println("my name is ",self.fcn.name)} }
|
|
v acts like a property to run f so C.v is the same as C.f()
|
|
class C{reg r} // C.r is compile time error
|
|
r:=5; // := syntax is same as "reg r=5", convenience
|