You are here: start » geeny » home » reference » language » flowcontrol

Function call expressions

Function call invokes an eval or a branch on the called object. Evals are first tested for a match, therefore, an eval will be executed when a branch of the same name exists.

  • obj1.func([p1 [, ..]])

Direct call to the function func of object obj. If funcion call has less parameters than required by definition, all undefined parameters are treated as if set nul (therefore, set to their default values). Parameters may be omitted, func(1, nul, nul, 2) is equivalent to func(1 , , , 2). Superfluous parameters are ignored.

  • obj1.(fname)([p1 [, ..]])

Indirect call. fname is the expression that generates the name of the called function.

  • @.func([p1 [, ..]])

Inherited call.

  • module_name::(fname)(...)
    module_name::fname(...)

Nested call to the specified script module. The branch executes with the same scope as branches that are local to object. If the branch cannot be found, the fallback branch ?() is called when existing. Inside the fallback, operator ‘?’ may be used to retrieve the called name.

Multiple calls with a single expression are possible when:

  • obj1 is a list of references instead of a single reference

All objects in the list are called, unless an interrupt is generated by one of the functions. The result of the last function call is returned, unless list operator ([]) encloses the call, in which case all the results are returned as ARRAY. The scope of results pointed to by the ARRAY is the same as of the local variables.

  • fname expression generates a list of atoms instead of a single atom

The object is called with all function names in the list.If obj1 is also a list, all objects are called, each with all functions in the list (N x M), unless an interrupt is generated by any of the functions.

  • listed parameters are fed into the call (array multi call)

When list operator ([]) encloses some or all parameters in a call, an array multi call is generated. Enclosed parameters are interpreted as lists, and a call is generated for each consequtive set of items in these lists. For a single object, single function call, the number of generated calls is equal to the item count in the biggest list. For a multiple object and/or multiple functions call, the same number of calls is generated as with non-array calls, however, each consequtive call is fed with the next consequtive set of items from the lists. If the number of items in the lists is insufficient, the items are either cycled through (default), the last item is repeated, or nul parameter is generated (causing the default value to be set when defined for the branch). Desired behavior may be selected with a compiler directive.

Explicit type conversion

  • TYPE{item} convert a single item (expression)
  • TYPES{item, item, ...} convert into a list of that type

Explicit type conversion is syntaxtically identical to calling a function. Therefore, items may be omitted, eg. FLOATS{1,0,2} is identical to FLOATS{1, ,2}

Examples

INTEGERS a          = INTEGERS{{0.5 15.6 22.8}, {10 20}, 100, {222 333}} 
//a                 = 0 15 22 10 20 100 222 333
 
INTEGER b           = INTEGER{27.8} 
//b                 = 27
 
ATOM c              = ATOM{10} 
//c                 = ‘TRUE’
 
ATOM d              = ATOM{0.0} 
//d                 = ‘’
 
ATOM e              = ARRAY{a , b , c , d} 
//e                 = pointers to 11 items of different types 
                      in lists a, b, c and d

Switch expression

switch ( selector , exp1 [, exp2 [, exp3 [, ..]]] )

Executes an expression selected by selector. The result of the expression is also the result of the switch.

If selector evaluates to integer 0, exp1 is executed. If it evaluates to 1, exp2 is executed, etc. If the matching expression does not exist, or if selector is less than 0, no expression is executed and nul is returned.

Calling switch is syntaxtically identical to calling a function. Therefore, expressions may be omitted, eg. switch(x, 1, nul, 2) is identical to switch(x, 1, , 2).

Interrupt expression

interruptz ( [expression] )

Interrupts a multiple call if expression evaluates to zero. Result is expression result, ie: return interruptz(result).

To generate an unconditional interrupt, use: interruptz().

interruptnz ( [expression] )

Interrupts a multiple call if expression evaluates to non-zero. Result is expression result, ie: return interruptz(result).

Using interruptnz without parameter has no consequences.

Single member access

reference.member

Direct access. In this case, member is the name of the prop.

reference.(member_name)

Indirect access. In this case, member_name is an expression that generates the name of the prop.

Single call

reference.function(...)
reference.(function_name)(...)
reference.member.function(...)
reference.(member_name).function(...)
reference.(member_name).(function_name)(...)

Multi member access

ARRAY result = references.member
ARRAY result = reference.(member_names)
ARRAY result = references.(member_names)

Multi member assignment

[references.member] = ...
[reference.(member_names)] = ...
references.(member_names) := ...
[references.member[list_ndx]] = ...
[reference.(member_names)[list_ndx]] = ...
references.(member_names)[list_ndx] := ...

Multi call

reference.(function_names)(...)
references.(function_names)(...)
reference.member.(function_names)(...)
reference.members.function(...)
reference.members.(function_names)(...)
 
(REFERENCES{references.members}).function(...)
(REFERENCES{references.members}).(function_names)(...)
(REFERENCES{reference.(members_names)}).(function_names)(...)
(REFERENCES{references.(members_names)}).(function_names)(...)
 
TYPE last_result = reference.(function_names)(...)
 
ARRAY result = [reference.(function_names)(...)]
ARRAY result = [references.(function_names)(...)]
ARRAY result = [reference.member.(function_names)(...)]
ARRAY result = [reference.members.function(...)]
ARRAY result = [reference.members.(function_names)(...)]
 
TYPES result = [reference.(function_names)(...)] ..

Array multi call

reference.function( par1, [par2], [par3], par4, ...)
references.function( [par1], par2, [par3], par4, ...)
reference.(function_names)( [par1], [par2], [par3], [par4], ...)
[reference.function( par1, [par2], [par3], par4, ...)]
[references.function( [par1], par2, [par3], par4, ...)]
[reference.(function_names)( [par1], [par2], [par3], [par4], ...)]
 
TYPES result = [visobj.function( par1, [par2] )]
INTEGERS result = INTEGERS{[visobj.function( par1, [par2] )]} + 10

If .. elseif .. else .. endif statement

if condition 
  [statements] 
[elseif condition
  [statements]]
[else 
  [statements]] 
endif

A condition is TRUE when the result of the expression evaluates to non-zero, a list with at least one element, a valid reference, or a valid atom (anything but nul atom).

While .. endwhile statement

while [condition] <loops if true, forever if ommited> 
  [statements] 
endwhile [condition] <loops if true, forever if ommited>

Flow control within a while block:

break

breaks a while block

continue

GOTO endwhile

For .. next statement

for [TYPE] iterator = list_expression
  [statements] 
next

Flow control within a for..next block:

break

breaks a for block

continue

GOTO next

Branch flow control statements

return [value]

Exits a branch and optionally returns a value .

 
geeny/home/reference/language/flowcontrol.txt · Last modified: 2008/02/08 13:05 by matija
Recent changes · Show pagesource · Login