Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Projectors ----- Up: Contents ----- Next: Common Interfaces


show notes
Features that need to be added to the page or ideas that haven't been thought out.
  • the Prototype object inherits from Object and its parameters define the slot names and types. Any two prototypes with the same slot names and slot types are considered to be of the same type.
  • inheritance is not possible, although inheritance of interfaces might be possible
  • properties to return all slot names in an object, or all values
  • property to query slots by name and type
  • might not use METHOD and EXTENDOBJECT, and just have prototypes be simple structures with slot names

The ability to add methods and extend objects may or may not be implemented but object creation using curly braces and keys will be a part of the language.

Tetra's type system can be used to declare powerful types for objects to be created from but this can lead to a lot of additional work to create simple objects that don't need all the type overhead. Prototypes provide a simple syntax for creating an object without first declaring a type. A block of slot::value pairs defines the name and value of each slot within the object and automatically generates a type. Slots may be explicitly typed by annotating their values.

	a := {x::0, y::0}
	echof("point = (%d, %d)\n", a.x, a.y)
The METHOD extension declares functions capable of accessing the object's slots.

METHOD (parameters) -> rtype body
  • parameters -- parameter list, parentheses required even when empty
  • -> -- required syntax when return type is given
  • rtype -- return type or list of return types, optional
  • body -- single or block expression
	a := {i::0, inc::method() return ++self.i}
Prototyped objects can be extended by shallow copying all slots from one object into another. Only individual objects may be extended and not entire classes, although multiple objects may be extended with a single command. Extended slots with the same names as those in the base object will cause an exception to be thrown.

EXTENDOBJECT object1 WITH object2
  • object1 -- unwrapped list of objects
  • WITH -- required syntax
  • object2 -- object to be copied into object1
	b := copyOf a
	extendObject b with {z::0}
	// a and b now have different types
	// object a has x,y slots
	// object b has x,y,z slots

	c := {angle::0}
	extendObject a with c
	// object a has x,y,angle slots

Previous: Projectors ----- Up: Contents ----- Next: Common Interfaces