Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Comparators ----- Up: Contents ----- Next: Cloning


Subtypes are implicitly cast to parent types when needed. Annotating an object with a type invokes the constructor and uses the object or tuple of objects as the constructor parameters, safely casting it to the type. If the constructor doesn't accept the object the compiler will attempt to destructure it and retry the constructor, safely casting its components.

Numeric literals are implicitly constructed to Number objects and the Number constructor accepts a Number object and uses internal rules to cast one Number to another. A runtime or compile-time exception is thrown if the conversion is invalid.

	a:Int = 1
	b:Float = a // valid
	a = b // invalid
	a = b.toInt() // valid
	c := a:Int8 // runtime exception if > 255

The Character type has a slot to get the unsigned value of a character and has the same speed as a C-style cast but has the appearance of a slot access. The `value constructor/setter produces a character object from an unsigned value.

	c:Char = 'a'
	n:Uint = c.value
	c = `value 0x61
	echo `value n:Char; // display 'a'

Previous: Comparators ----- Up: Contents ----- Next: Cloning