Advanced Computing Environment
brix-os project page
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.
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;// displays 3
b := [[1,2], [3,4]] echo b[1,0];// displays 3
Copyright © 1995-2017 Brand Huntsman