up previous next
2.2.17 More First Functions
A user-defined function can have any number of parameters of any type, even a variable number of parameters. Note that even a function with no parameters must be called with parentheses.

Example
  Define Test1()
    PrintLn "This is a function with no parameters.";
    For I := 1 To 10 Do
      Print I^2, " ";
    EndFor;
  EndDefine;
  Test1();
This is a function with no parameters.
1 4 9 16 25 36 49 64 81 100
-------------------------------
  Define Test2(...)  -- a variable number of parameters
    If Len(ARGV) = 0 Then -- parameters are stored in the list ARGV
      Return "Wrong number of parameters";
    Elsif Len(ARGV) = 1 Then
      Print "There is 1 parameter: ", ARGV[1];
    Else
      Print "There are ", Len(ARGV), " parameters: ";
      Foreach P In ARGV Do
        Print P, " ";
      EndForeach;
    EndIf;
  EndDefine;
  Test2(1, 2, "string",3);
There are 4 parameters: 1 2 string 3
-------------------------------