Function Parameters

Prev Next

Introduction

B4P applies a flexible scheme to specify parameters to be passed into functions.

  • Functions may accept a fixed or variable number of parameters.
  • Variable number of parameters is typically specified with a minimum, maximum and incremental count, Example: min 3, max 9, and increments of 2, so even number parameters are rejected.
  • If 0 parameters are allowed, then functions called as procedures can be specified without parentheses, e.g. echo;.
  • Following parameter directions are supported: input, output, input/output, and variable references
  • Function parameters can be values, variables (including references to variables), expressions, table references and code pieces.

Details are ruled in the respective function definitions.

Type checking of function parameters takes place at run-time. Depending on the parameter requested, a specific type (e.g. numeral), multiple different types, or all types are accepted. Various functions dealing with tables do also accept table columns as function parameters which is a flexible parameter type and accepts one of the following: individual header names, individual column numbers or several of them provided in a parameter set.

The ability to pass code pieces as parameters into functions, which are then executed by the function once or repeatedly on when needed, are unique to B4P and not common in other programming languges. This feature is actually used in control flow functions (e.g. if(), while(), etc.) which are, in other languages, defined as fixed keywords and are inherent parts of the programming language. In addition, this feature allows convenient operations through tables without specifying loops, e.g. with the table process() function.