extend String def zero as int return 0 def doubleLength as int return .length * 2 def appendedBy(s as String) as String return String.concat(this, s) to ! # interesting. cannot use: this + s class A def one as int return 1 extend A # extend a class that exists in the source (not a library) def two as int return 2 # extend a struct extend DateTime def isOddYear as bool return .year % 2 == 1 def isEvenYear as bool return not .isOddYear # reference same method in same extension struct SA def one as int return 1 extend SA def two as int return 2 # extend an interface extend IComparable def equalTo(obj as Object?) as bool return .compareTo(obj) == 0 class Number implements IComparable var n as int cue init(n as int) base.init .n = n def compareTo(obj as Object?) as int if obj inherits Number return .n - obj.n else return -1 # extend a qualified type extend System.TimeSpan def isCloseToZero as bool return .totalSeconds < 0.1f class Program def main is shared s = 'aoeu' assert s.zero == 0 assert s.doubleLength == 8 assert s.appendedBy('1') == 'aoeu1' a = A() assert a.one == 1 assert a.two == 2 assert DateTime(2007, 1, 1).isOddYear assert DateTime(2008, 1, 1).isEvenYear sa = SA() assert sa.one == 1 assert sa.two == 2 assert .checkIComparables(Number(5), Number(5)) assert not .checkIComparables(Number(5), Number(-5)) assert DateTime.now.subtract(DateTime.now).isCloseToZero def checkIComparables(a as IComparable, b as IComparable) as bool is shared return a.equalTo(b)