Definition of user functions
In OWBasic it is possible to define user functions.
User functions and procedures must be defined at the start of the program. The main program always begins after that.
A function definition begins with the procedure heading and ends with the keyword RETURN.
FUNC test A, B#, VAR C
<statements>
RETURN <value> |
The function heading begins with the keyword FUNC, followed by the name of the function and the parameter list. The type of the function is determined by the suffix of the function name as with variables if it is not the default type.
The parameter list describes the parameters of the function.
Variables used within the procedure are local, i.e., outside of the procedure they are unknown.
Functions calculate a value und return this value to the caller. They can be used as part of an expression. The value which a function returns, has to be given with the RETURN statement, which terminates the function definition.
The use of user functions is the same as for builtin functions. A user defined function is used also, if a builtin function with the same name exists.
Example:
FUNC vlen x,y: ! length of 2d vector
RETURN sqr(x*x+y*y)
x=5: y=7: ! These variables do not have to do anything with
! the function parameters.
print vlen(x-5,y-2): ! Example-Call |
|