To define functions by an user himself, `def' statement must be used. Syntactical errors are detected in the parsing phase of Asir, and notified with an indication of where Asir found the error. If a function with the same name is already defined (regardless to its arity,) the new definition will override the old one, and the user will be told by a message,
afo() redefined.
on the screen when a flag verbose is set to a non-zero value by
ctrl().
Recursive definition, and of course, recursive use of functions are
available.
A call for an yet undefined function in a function definition is not
detected as an error. An error will be detected at execution of the
call of that yet undefined function.
def f(X) {
if ( !X )
return 1;
else
return X * f(X-1);
}
def c(N)
{
A = newvect(N+1); A[0] = B = newvect(1); B[0] = 1;
for ( K = 1; K <= N; K++ ) {
A[K] = B = newvect(K+1); B[0] = B[K] = 1;
for ( P = A[K-1], J = 1; J < K; J++ )
B[J] = P[J-1]+P[J];
}
return A;
}
def add(A,B)
"add two numbers."
{
return A+B;
}
In the second example, c(N) returns a vector, say A, of length
N+1. A[I] is a vector of length I+1, and
each element is again a vector which contains
as its elements.
help.
In the following, the manner of writing Asir programs is exhibited for those who have no experience in writing C programs.
Go to the first, previous, next, last section, table of contents.