Function definitions have the form:
function-definition:
function-declarator function-body
function-declarator:
func identifier
proc identifier
function-body:
{ para-aliasopt local-var-declopt statement-listopt }
para-alias:
para identifier-listopt ;
local-var-decl:
auto identifier-listopt ;
identifier-list:
identifier
identifier , identifier-list
The identifier is declared to be a
function using the keywords func or
proc. There is no difference between func and proc. The word proc is more
meaningful when the function serves as a procedure, i.e. a function which
does not return a value.
$ (dollar sign); notice that there is
no parameter list after the identifier.
The first argument is $[1], the second argument
is $[2], and so forth. For convenience,
$[1], $[2], ... can be replaced
by $1, $2, ... .
para
gives nicknames to the parameters.
The first identifier
in para-alias matches $1 and so forth.
The number of identifiers does
not required to match the number of actual parameters. $n can be referenced
by either $n, $[n]
or the nickname given.
$# is the current number of arguments.
List operations are applicable to $.auto
(means dynamically allocated). All
local variables are RWV's. There is no need to declare the type of local
variables because EDEN does the run-time type checking. The syntax is:
auto identifier-list ;where identifier-list is a list of identifiers separated by commas.
return expressionopt ;If the expression is omitted,
@ will be
returned. Flowing off the end
of a function is equivalent to return @.func
can be replaced by proc. There are
no differences between these two keywords. Thus they can be interchanged.
The purpose of having another keyword is to self-comment the program.
It is intended (not restricted) that func should be used for defining
side-effect-free operators.
func max /* returns the max. value of its arguments */
{
para m; /* m is the first argument $1 */
auto i; /* declare local variables */
for (i = 2; i <= $#; i=i+1) {
/* for the other arguments */
if ($[i] > m) /* the ith argument */
m = $[i];
}
return m; /* returns max to the caller */
}
defines a function named max which
returns the maximum value of its arguments.MaxNumber = max(0,i,j,k);evaluates the maximum value of
0, i,
j and k, and stores the results
in the RWV MaxNumber. The parentheses cannot be omitted even if no arguments
are passed to the function.F = max;then the statement
MaxNumber = F(1,3,2);assigns
3 to MaxNumber.
G = [ min, max ];where min is supposed to be a function that returns the minimum value of its arguments, then
Num = G[n](1,3,2);
Num will have the value 1 if n is 1
(G[1]=min), 3 if n is 2
(G[2]=max).