Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Properties ----- Up: Contents ----- Next: Methods


show notes
Features that need to be added to the page or ideas that haven't been thought out.
  • need a way to automatically invoke a method after writing to a slot. when multiple slots are consecutively written to and all share the same method callback, the compiler can invoke the method a single time after the writes.

A slot is a data field inside an object and the type definition describes what slots an object will contain. All slots are declarations and therefore don't need the := operator. Types must declare atleast one slot or inherit a type with a slot before they can be instantiated.

Slots default to mutable and may be modified with `ref, `nullable, `const, `private and `protected flags. Constant slots are read-only for all code after initialized. Private slots are only accessible by methods. Protected slots are mutable for methods and read-only for external code.

flags SLOT name = value
  • flags -- optional flags to modify slot
  • name -- slot name and optional type annotation
  • = -- required syntax
  • value -- required initializer value
  • `private -- private slot
  • `protected -- internally mutable, externally immutable slot
  • `const -- immutable slot
  • `ref -- reference slot
  • `nullable -- nullable reference slot

Slots are accessed as members of the object for external code or members of the self parameter in methods.

	Foo := deftype () {
	  constructor (x:Int)
	  slot x = x
	  method clear() self.x = 0 // access via self
	a:Foo = 1
	a.x = 2 // external slot access
Dynamically sized slots prevent further slots from being declared as they must be the last slot in the object. These slots should be declared as references if the type must be extended in a subtype.

Using Properties
All type properties, including Self, are available for slot types and values. The above example shows the private x property defined by the constructor being used to initialized the slot.

Previous: Properties ----- Up: Contents ----- Next: Methods