Function Call Expressions
Starting with version 1.0.7 functions may be called in 'function call syntax' as a value expression.
The previous calling convention (as described above) is "procedural" where function calls behave like commands.
Function Call Expressions look like and behave more like traditional language functions.
The return value can be any value type (including XDM values such as sequences, elements etc). Evaluating a function call evaluates to the return value.
Arguments are passed in Function Call expressions with ( arglist ).
For example, A function that concatenates 2 arguments separated by ":"
function concat() { return "$1:$2" ; } echo concat(hello world)
Result
hello:world
Function call expressions can be assigned to variables
a=concat(hello world) echo $a
Since they are value expressions they can nest and recurse.
a=concat( concat(this that) another)
Result
this:that:anoother
Arguments are expanded exactly like command execution. The output of the function is shared with the output of the calling shell the same as in procedural calling.
Example
function list() { echo $* return $# } a=list(*.c) echo There were $a .c files
Result
foo.c bar.c spam.c There were 3 .c files
Java Objects
Functions can consume, operate on, and produce Java ObjectsExample:
Note this demonstrates types of function call syntax and passing java objects.
function today() { return jnew( java.util.Date ) } function printDate() { date=$1 echo date.toString() } printDate today()
Result
Thu Nov 18 11:15:43 EST 2010
CoreSyntax
Commands
Functions
SyntaxFunction