Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Types ----- Up: Contents ----- Next: Slots


Properties are the set of slots and methods in a Type object and may be public or private and parameter or value. Parameter properties are declared in the type parameter list, define the structures of the resulting data objects and are carried along in the type information for each object. The value properties are mere data or functions accessible in the type namespace and do not exist in the type information. All properties are declaration only (and immutable) and don't use the := operator.

Object methods and function properties that use properties, transparently pull in the type information through the $Self parameter and each property is directly accessible with the $ operator. Each parameter property is available without the $ operator in method and function interfaces.

	Foo := deftype (n:Int) {
	  constructor (x)
	  slot x = x
	  method getSelf() return $Self
	  bar = 3
	  baz = def () return $n + $bar
	f := Foo(1)
	echo f.n; // displays 1
	echo; // displays 3
	echo f.baz(); // displays 4
	a:Foo(1) = 2
	(echo a.x (typeOf a).n) // displays 21
The above example has a public parameter property n, a private value property x (constructor parameter) and public value properties bar and baz. Slot and method names exist in a separate namespace and don't collide with properties.

Flags available for value properties:

Properties can be used to create additional named constructors that process data before passing it along to the primary constructor. Collections use properties to generate objects capable of iterating over the collection. Properties must be used to construct types that have parameterless constructors. And shadow properties are the most important usage, mapping fast compile-time extensions over slower runtime functions.

Parameter properties from interfaces only modify the interface and are not inherited. The interface may however require subtypes to have specific parameter and value properties. See the Collections page for an example. The `shadow flag is only available for implementations and can not be used for interfaces as it has no meaning.

Previous: Types ----- Up: Contents ----- Next: Slots