Advanced Computing Environment
Hosted by SourceForge
brix-os project page

Previous: Accessors ----- Up: Contents ----- Next: Comparators

Compound Accessors

Tetra offers another type of accessor that treats the object as a function with parameters. Functions and arrays are the most common examples of types with compound accessors. Like constructors, the style of parameter list (parentheses, braces or brackets) determines the compound accessor style. The parameter list must not have whitespace between it and the object in order to invoke the compound accessor. The COMPOUND extension invokes the DEFX which processes the parameters and body and then returns an extension which COMPOUND stores in the type. Therefore, a compound accessor can do anything an extension can but also has a self parameter to access the object.

COMPOUND `open (parameters) -> rtype X-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
  • X-body -- single or block expression

A function name is evaluated as a Function object and the presence of a parenthesis-style parameter list invokes its compound accessor to evaluate the parameters and generate a function call. The Array compound accessor uses a bracket-style parameter list of indices and returns elements within the array.

	// Function compound accessor
	foo(1, 2)

	// Array compound accessor
	a := [1,2,3,4,5]
	echo a[2]; // displays 3
	b := [[1,2], [3,4]]
	echo b[1,0]; // displays 3

Previous: Accessors ----- Up: Contents ----- Next: Comparators