-
Notifications
You must be signed in to change notification settings - Fork 89
Macro operators
Alex Zimin edited this page Jul 11, 2011
·
3 revisions
mutable i = 0;
i++;
assert(i == 1);
mutable i = 0;
i--;
assert(i == -1);
assert(3 ** 4 == 81);
assert((true && true) == true);
assert((false && false) == false);
assert((false && true) == false);
assert((true && false) == false);
assert((true || true) == true);
assert((false || false) == false);
assert((false || true) == true);
assert((true || false) == true);
assert((0 %|| 0) == false);
assert((0x01 %|| 0x10) == true);
assert((0x01 %|| 0x01) == true);
assert((0x10 %|| 0) == true);
assert((0 %&& 0) == false);
assert((0x01 %&& 0x10) == false);
assert((0x01 %&& 0x01) == true);
assert((0x10 %&& 0x11) == true);
assert((1 %^^ 0) == true);
assert((0 %^^ 0) == false);
assert((1 %^^ 1) == false);
assert((0 %^^ 1) == true);
mutable i = 1;
i += 2;
assert(i == 3);
mutable i = 3;
i -= 2;
assert(i == 1);
mutable i = 3;
i *= 2;
assert(i == 6);
mutable i = 6;
i /= 2;
assert(i == 3);
mutable i = 7;
i %= 2;
assert(i == 1);
mutable i = 0x0F;
i <<= 8;
assert(i == 0xF00);
mutable i = 0xF00;
i >>= 4;
assert(i == 0x0F0);
mutable i = 0xF0;
i |= 0x0F;
assert(i == 0xFF);
mutable i = 0xFA;
i &= 0x1F;
assert(i == 0x1A);
mutable i = 1;
i ^= 0;
assert(i == 1);
i ^= 1;
assert(i == 0);
mutable a = 1;
mutable b = 2;
a <-> b;
assert(a == 2);
assert(b == 1);
mutable a = [2, 1];
a ::= 3;
assert(a == [3, 2, 1]);
def a = [2, 1];
def b = a.Map(element => element * 2);
assert(b == [4, 2]);
def a : int? = null;
def b = a ?? 42;
assert(b == 42);
def a : int? = 88;
def b = a ?? 42;
assert(b == 88);
def a : string = null;
def b = a ?? "default value";
assert(b == "default value");
def a : string = "some value";
def b = a ?? "default value";
assert(b == "some value");
class A { public i : int = 2; }
class B { public a : A = null; }
class C { public a : B = null; }
def b1 = B();
assert(b1?.a?.i == 0); // 0 is a default value of int (type of i field)