Contents | Index | < Browse | Browse >
2.9 Functions

  A function is defined as follows:
  +-----------------------------------------------------------------------------
  | 
  | Function.t [FAST] name {param.t, ...}
  |   Function Return value
  | End Function
  |
  | Statement [FAST] name {param.t, ...} 
  | End Statement
  | 
  +-----------------------------------------------------------------------------
  
  Function/Statement: keyword to indicate we are defining a function
  FAST          : optional modifier
  name          : function's name
  .t                     : type extension
  value         : expression we want to return
  param.t, ...  : list of parameters, can be none up to 10

  Example:
  +-----------------------------------------------------------------------------
  | 
  | Function.f AddTwoFloats{a.f, b.f}
  |   result.f = a + b
  |   Function Return result
  | End Function
  | 
  | Statement PrintLine{text.s}
  |   Print text.s,"\\n"
  | End Statement
  |
  +-----------------------------------------------------------------------------

2.9.1 Statements

  If the function has no return value, the keyword "Statement" is used instead
  of "Function". There is no need for a "Statement Return", unless the function
  should be exited earlier than the "End Statement".

2.9.2 Optional Parameters

  A function can have optional parameters. The optional parameters
  are declared by using the "@" (at sign). Once a parameter is optional,
  all following parameters must be optional too.
  Optional parameters that are omitted will be filled with the default value -1
  if they are numeric (integers and floats), and the empty string if they are
  strings.

  Example:
  +-----------------------------------------------------------------------------
  | 
  | Function.l AddLongs{a.l, @b.l, @c.l}
  |   Function Return a+b+c
  | End Function
  |
  | Function.l ConcatStrings{a.s, @b.s, @c.s}
  |   Function Return a+b+c
  | End Function
  |
  | Print AddLongs{3,2}                  ; this would output "4" (yes, "4")
  | Print ConcatStrings{"Hello","World"} ; this would output "HelloWorld"  
  |  
  +-----------------------------------------------------------------------------
  
  There is no possibility to overload a function.
  
2.9.3 FAST Modifier

  The FAST modifier directive removes the init code of variables from the
  function.
  The following restrictions apply:
  - All local variables must be initialized manually.
  - Strings and newtypes are not allowed anymore.
  Therefore, the calling overhead of the function is reduced to a minimum.
  This makes sense for short and high frequently called functions.


Contents | Index | < Browse | Browse >