Glich - v0.3.0 Manual
Define object
Development v0.3.0 Manual Glich Script Statements Define object

Statement: object

An object statement defines an object type which can later be used to create an object value. An object value is an array of other values which can referenced by number or given names. An object value also has a code name which is the name of the object type. Additionally functions can be defined which can be called using the function operator '@'.

The following sub-statements can be used in an object definition. All are optional.

object Sub-Statement List
Sub-StatementUse
nameA short descriptive name for the object to expand its code name.
valuesA list values that are used as local variables.
functionAs normal function but has access to the values.
object Statement
ExampleOutput
object complex { name "Complex number"; values real imaginary; function add( comp ) { if @object( comp ) = "complex" { result = {complex real+comp[real], imaginary+comp[imaginary]}; } else { result = error "Must have 'complex' argument"; }; }; }; let c1 = {complex 5, 9}; let c2 = c1@add( {complex 20, 6} ); write c1, c2 nl; write c1 @ add( c2 ) nl; write c1 @ add( 1 ) nl; {complex 5, 9}, {complex 25, 15}
{complex 30, 24}
Error (9): Must have 'complex' argument

Sub-Statement: name

The name sub-statement provides a short descriptive name for the object. This name can be used to expand the object's code name.

Sub-Statement: values

The values sub-statement consists of a list of names terminated with a semicolon. These are the names given to the fist values, in the order given.

The values in the object value array can be accessed or assigned to by using the subscript '[' ']' operator.

Sub-Statement: function

The function sub-statement is similar other functions except it has access to the objects values and it is instigated with the function '@' operator following an object value.

Development v0.3.0 Manual Glich Script Statements Define object

Managed by WebPageLayout Validated by HTML Validator (based on Tidy)

9th March 2023