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. Additionally functions can be defined which can be called using the function operator '@'.

Two sub-statements can be used in an object definition. Both are optional.

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

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