As mentioned earlier, "function" in BEE is like "procedure" in traditional sense because it does not work syntactically as a value (like a = func(b) as in other computer languages.) Here are the main differences between BEE "function" and traditional one:
n Argument list is specified in name-value pairs, not enclosed in a pair of small brackets.
n Arguments are not positional. Their order of appearance (in both declaration and calling) is not significant.
n Arguments are all optional and do not need to be declared in the function declaration line unless you want to assign the argument with a default value. (The function can check whether an argument value is available using the "isset" Conversion.)
n Arguments are all passed by value. If you want the change of an argument value to survive the function exit, the variable name should be passed and the variable that such name refers to should be declared "parent" (linked with the caller's scope).
n Arguments are evaluated before being passed to a function unless when they are passed by "absolute" value (indicated by a '!' in front of the argument name in either the declaration line or the calling line.)
n Variables (also called context or environment) inside the function are local except for those in system classes and those explicitly or implicitly declared "global" or "parent".
n Results are made available via several special variables: result%function, status%function and message%function. They are all arrays (as always), and are referenced in the parent's scope as result%funcname, status%funcname and message%funcname.
n Function names will be converted to lowercase internally and therefore is not case sensitive.
Let's see another hello-world example:
function helloworld whosays="Somebody" {
display '{arg%whosays} says "Hello World"<br>\n';
}
helloworld whosays="Bill Gale"; // Output: Bill Gale says "Hello World"
helloworld; // Output: Somebody says "Hello World"
|