' Display characters DEF FUNC PRINT "SAMPLE" END ' Call FUNC
If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.
・The parameter name specified here can be used as a variable in DEF-END.
' Display characters at the specified position DEF FUNC2 X,Y LOCATE X,Y PRINT "SAMPLE" END ' Call FUNC2 10,4
If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.
・The parameter name specified here can be used as a variable in DEF-END.
When you want a value to return to the caller as a result, specify it as using the RETURN command in DEF-END. (description like RETURN ANS)
'Addition DEF ADD(X,Y) RETURN X+Y END ' Factorial calculation using recursion DEF FACTORIAL(N) IF N==1 THEN RETURN N RETURN N*FACTORIAL(N-1) END ' String inversion DEF REVERSE$(T$) VAR A$="" 'Local string VAR L=LEN(T$) 'Local WHILE L>0 A$=A$+MID$(T$,L-1,1) DEC L WEND RETURN A$ END ' Call PRINT ADD(10,5) PRINT FACTORIAL(4) PRINT REVERSE$("BASIC")
If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.
・The parameter name specified here can be used as a variable in DEF-END.
Describe as many variable names as you want to return as a result after OUT
・By storing a value to the variable specified here in DEF-END, the value can be returned to the caller.
' Addition and multiplication DEF CALCPM A,B OUT OP,OM OP=A+B OM=A*B END ' Call CALCPM 5,10 OUT P,M PRINT P,M
・It is possible to make only the parameter variable-length, or make the return value variable-length.
You can declare that the number of parameters is variable-length by writing * (asterisk) after the command name.
・Use DEFARGC, DEFARG, TYPEOF to investigate the number, content, and type of parameters.
Write * (asterisk) after OUT to declare that the number of return values is variable-length.
・You can use DEFOUTC and DEFOUT to investigate the number of return values and set the return value.
DEF VARFUNC * OUT * FOR I=0 TO DEFOUTC()-1 DEFOUT I, DEFARG(I)*2 NEXT END