Revision [1912]

Last edited on 2014-06-08 18:23:14 by DavidLee
Additions:
The Return value of a function is the return value of the last command, or the argument of the [[CommandReturn return]] function. Return values can be any type,
including XML and object types. If the return type is numeric it is available as $? when run using command syntax. Any value is available when executed using [[SyntaxFunctionCall Function Call Syntax]]
Deletions:
The Return value of a function is the return value of the last command, or the argument of the [[CommandReturn return]] function. Return values can be numeric only (signed integer).


Revision [1575]

Edited on 2010-11-18 11:11:37 by DavidLee
Additions:
See [[SyntaxFunctionCall Function Call Syntax]]
Deletions:
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 ":"
%%(shell)
function concat()
return "$1:$2" ;
echo concat(hello world)
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)
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.
%%(shell)
function list()
echo $*
return $#
a=list(*.c)
echo There were $a .c files
foo.c bar.c spam.c
There were 3 .c files
===Java Objects===
Functions can consume, operate on, and produce [[JavaObjects Java Objects]]
Example:
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()
%%
Thu Nov 18 11:15:43 EST 2010


Revision [1555]

Edited on 2010-11-18 08:17:51 by DavidLee
Additions:
[[Functions]]


Revision [1554]

Edited on 2010-11-18 08:17:28 by DavidLee
Additions:
Functions can consume, operate on, and produce [[JavaObjects Java Objects]]
Deletions:
Functions can consume, operate on, and produce [[NativeJava Java Objects]]


Revision [1553]

Edited on 2010-11-18 08:16:41 by DavidLee
Additions:
===Java Objects===
Functions can consume, operate on, and produce [[NativeJava Java Objects]]
Example:
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()
%%
Thu Nov 18 11:15:43 EST 2010


Revision [1551]

Edited on 2010-11-18 08:09:36 by DavidLee
Additions:
=====Declaring Functions=====
====Function Call Expressions====
Deletions:
====Expermental - Function Call Expressions====


Revision [1471]

Edited on 2010-06-25 08:54:38 by DavidLee
Additions:
foo.c bar.c spam.c
Deletions:
foo.c
bar.c
spam.c


Revision [1470]

Edited on 2010-06-25 08:52:07 by DavidLee
Additions:
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.
function list()
echo $*
return $#
a=list(*.c)
echo There were $a .c files
foo.c
bar.c
spam.c
There were 3 .c files


Revision [1469]

Edited on 2010-06-25 08:49:39 by DavidLee
Additions:
====Expermental - 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 ":"
%%(shell)
function concat()
return "$1:$2" ;
echo concat(hello world)
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)
this:that:anoother


Revision [1410]

Edited on 2010-05-14 03:46:23 by DavidLee
Additions:
This declares a function "name". The different variations in syntax are equivalent. The body of the function when executed runs in the same context as the parent shell, with the exception of Positional Parameters ($1 ... $N).
Deletions:
This declares a function "name". The body of the function when executed runs in the same context as the parent shell, with the exception of Positional Parameters ($1 ... $N).


Revision [1409]

Edited on 2010-05-14 03:45:35 by DavidLee
Additions:
Variables can be marked local using the "local" keyword. Local variable modifications are scoped to the function (and any function or script it calls) and do not affect the global (or parents) variables of the same name.
The Return value of a function is the return value of the last command, or the argument of the [[CommandReturn return]] function. Return values can be numeric only (signed integer).
Deletions:
As with bash, variables can be marked local using the "local" keyword. Local variable modifications are scoped to the function (and any function or script it calls) and do not affect the global (or parents) variables of the same name.
The Return value of a function is the return value of the last command, or the argument of the [[CommandReturn return]] function.


Revision [1403]

Edited on 2010-05-13 09:45:28 by DavidLee
Additions:
=====Local Variables=====
As with bash, variables can be marked local using the "local" keyword. Local variable modifications are scoped to the function (and any function or script it calls) and do not affect the global (or parents) variables of the same name.
setit ()
{
local A=$1
echo in setit A is $A
A=Value1
setit Value2
echo Outside of setit A is $A
Results
in setit A is Value2
Outside of setit A is Value1


Revision [1402]

Edited on 2010-05-13 09:42:00 by DavidLee
Additions:
Note: prior to version 1.0.5 "function name ()" and "name ()" behaved differently. The former syntax caused all variable references to be local.
From version 1.0.5 onwards this has been fixed to conform to the behaviour of bash/ksh where variables are all global unless the "local" modifier is used.
Deletions:
Note: prior to version 1.0.5 "function name ()" and "name ()" behaved differently.


Revision [1401]

Edited on 2010-05-13 09:22:35 by DavidLee
Additions:
Functions can be declared in two forms, with or without the keyword "function". These forms behave identically.
Note: prior to version 1.0.5 "function name ()" and "name ()" behaved differently.
===function name { list; }===
Note: starting with version 1.0.5 local variables can be defined.
Deletions:
Functions can be declared in two forms, with or without the keyword "function". These are the equivalent to the forms for ksh.
This declares a function "name". The body of the function when executed runs in the a child shell context. Arguments are passed as positional parameters ($1 .. $N)
This means that variables assigned within the function *do not* have a "side effect" of writing into the global environment for the current shell.
function setit ()


Revision [1354]

Edited on 2010-05-02 09:15:58 by DavidLee
Additions:
======Return Value======
The Return value of a function is the return value of the last command, or the argument of the [[CommandReturn return]] function.
foo ()
{
true ;
foo && echo Is True
Is True
foo ()
return 2 ;
foo
echo $?
2


Revision [1353]

Edited on 2010-05-02 09:13:18 by DavidLee

No Differences

Revision [1352]

Edited on 2010-05-02 09:12:13 by DavidLee
Additions:
===name () { list; }===
===function name () { list; }===
Deletions:
=====name () { list; }=====
=====function name () { list; }=====


Revision [1351]

The oldest known version of this page was created on 2010-05-02 09:11:52 by DavidLee
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki