# DEFFUN

Updated: 10/19/2021, 9:29:48 PM
Created: 10/19/2021, 9:29:48 PM
Last Updated By: Kevin Munoz
Read Time: 1 minute(s)

# Description

This statement is used to declare an external function to the jBASE BASIC compiler and optionally define its arguments. The statement is used in the program that calls the function. It takes the general form:

DEFFUN FuncName({ {MAT} Argument1, {MAT} Argument2...})
1

Where

  • FuncName is the name used to define the function. It must be the same as the source file name.
  • Argument specifies a value passed to the function by the calling program. To pass an array, you must use the MAT before the argument name. These parameters are optional (as indicated in the Command Syntax) but can be specified for clarity. Note that if the arguments are not initialized somewhere in the program you will receive a compiler warning.

# Note

The DEFFUN statement identifies a user-written function to the jBASE BASIC compiler, which must be present in each program that calls the function, before the function is called. A hidden argument is passed to the function so that a value can be returned to the calling program. The return value is set in the function using the RETURN (value) statement. If the RETURN statement specifies no value then the function returns an empty string.

An example of use is as follows:

  • Main program:
DEFFUN Add()

arg1 = 10
arg2 = 20

sum = Add(arg1, arg2)

CRT sum

arg3 = RND(42)
arg4 = RND(24)

CRT Add(arg3, arg4)
1
2
3
4
5
6
7
8
9
10
11
12
13
  • Function:
FUNCTION Add(operand1, operand2)
    result = operand1 + operand2
RETURN(result)
1
2
3

Go back to jBASE BASIC

Go back to Programmers' Reference Guide