Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 6.05 KB

File metadata and controls

66 lines (47 loc) · 6.05 KB

Documentation

Functions


// Call

[name]([function call, relation, expression, term or factor])

// Definition

function [name]([parameter], [parameter], ..., locals: [local], [local], ...)
  [statement]
  emit [function call, relation, expression, term or factor]
done

A function is a reusable group of statements identified by a unique name that perform a task and can return a value. BIPLAN supports up to 87 functions, each capable of hosting up to 87 parameters and local variables. Function definitions must be defined after the stop keyword.

Function definitions are identified by the function keyword followed by a unique name; parameters and local variables are defined within the following parentheses, local variables are defined after the locals: keyword. Names of functions and parameters must not start with a number, must be composed by lowercase and or uppercase letters, numbers and or the symbol _. The value of uninitialized parameters and local variables is guaranteed to be 0.

When the emit keyword is encountered the function returns the result of the following function call, relation, expression, term or factor. All statements contained in the function definition are executed until done is encountered. The done statement must be one and must be the last statement of the function.

// Call

average(10, 20); // Returns 15

// Definition

function average($a, $b, locals: $sum)
  $sum = $a + $b
  return $sum / 2
done

Functions can receive only numeric parameters, each parameter can represent a numeric value, a reference to a variable or a reference to a string:

:test = "test"

capitalize(index :test)

print :test // Prints "Test"

stop

function capitalize($string_addr)
  :[$string_addr][0] = :[$string_addr][0] - 32
done

In the example above the reference to the string :test is passed to the capitalize function. The reference is then used to modify the first character.