Methods and Functions

Function and class method declaration is the biggest difference between Origo and existing well known programming languages. There's no definitive "method name" in Origo, but the parameters are mixed within the name text.

(About the terminology. In the present document, name method means the function members of the classes, and functions are the global functions outside any class like the program entry point main.)

Parameters

A function consists of any number of words (text parts) and parameters, which are separated from each other with spaces. Parameters are written inside angle brackets < >. Here's an example of a method definition:

(int) base <int base> to power <int exponent>

The definition above taks two parameters: base and exponent. Parameter data type specifier precedes the actual variable name, like int before base.

Return value

If a function has a return value it is written in parentheses ( ) in the beginning of the definition.

A Function Call

The function is called simply by entering suitable values (or arguments) in place of parameter definitions, and storing the possible return value if needed. For instance, the function above is called:

int power = base 5 to power 7

Example: A global function.
// Let's define a function that takes two parameters 'base' and 'exponent'
// and returns an int. Return value is 0 if any error occurred, otherwise 
// it returns the 'base' raised to the power 'exponent'.
(int) base <int base> to power <int exponent>
  
  // Function body starts here. Note the indentation
  
  // Let's check that the parameters are non-negative integers, 
  // because in this simple example we don't want to handle all special cases.
  if base < 1 or exponent < 0
    return 0
                         
  int result = 1
  
  int i = 0
  while i < exponent
    result *= base
    i++
  
  // Let's return the result by return statement.
  return result

The Program Entry Point

Global function main is a mandatory function in every program. It is the program entry point where the execution of the program always starts.

Example (continues): The program entry point and calling of a function.
// Function 'main' is a mandatory entry point in every Origo program.
// It does not have a return value
main                           
  
  // This is a call to the function we defined above
  // Let's raise number 5 to power 7
  int result = base 5 to power 7 
                               
  print result                      // Prints 78125
  
  // In a real application use the more efficient 
  // and extensive power operator ** of the Origo API
  print 5 ** 7                      // Prints 78125.0
  
  // Note that the empty return statement as below is optional in a 
  // void function. I write it here to emphasize the end of the function.
  return