local IntervalTimer timer() sleep(1500) println( timer ) # prints: 1.50 seconds
overlaying aspect MainDebug
METHODS
method init:
println( "+init" )
underlying
println( "-init" )
endAspect
augment Main : MainDebug;
can now be written like this:
overlaying augment MainDebug
METHODS
method init:
println( "+init" )
underlying
println( "-init" )
endAugment
class Alpha
PROPERTIES
a = 5 : Int32
endClass
class Beta : Alpha
PROPERTIES
b = 5 : Int32
METHODS
method init_object:
println( "Hello World" )
endClass
into this:
class Alpha : Object
PROPERTIES
a : Int32
METHODS
method init_object:
prior.init_object
a = 5
endClass
class Beta : Alpha
PROPERTIES
b = 5 : Int32
METHODS
method init_object:
prior.init_object
b = 5
println( "Hello World" )
endClass
init_object() methods are automatically called when an object is created and before the regular init() methods.
enum DIRECTION : BitFlags<<DIRECTION>>
CATEGORIES
north(1), east(2), south(4), west(8)
endEnum
...
local DIRECTION d = DIRECTION.north | DIRECTION.east
println( d == DIRECTION.north ) #prints: false
println( d.includes(DIRECTION.north) ) #prints: true
println( d ) #prints: north,east
println( d.flags ) #prints: 3
d &= !DIRECTION.north
println( d ) #prints: east
println( d == DIRECTION.east ) #prints: true
println( d.flags ) #prints: 2
VARS
a=5, b : Int32
METHODS
method init_object:
b=6
If you create an object of this class then b=6 and a=5. If you extend a second class and don't define init_object() then a=5 and b=0. If you define init_object() and call "prior.init_object" then b=6, a=5, and a=5 (two calls).
# Change C-style hex literals into assembly-style ones, e.g.:
# 0x2AC → 2ACh
local Pattern hex_pattern( "'0x' { (digit or ('a'..'f') or ('A'..'F'))+ }" )
src_code.replace( hex_pattern, "$[0]h" )
method insert( Int32 before_index, Object data ):
require( before_index >= 0 and before_index < this.count )
ensure( this.count == old.count + 1 )
if (before_index == count)
add( data )
else
...
endIf