You must start your PROCEDURES with the PROCEDURE keyword. Next it must have a name that doesn't appear in another PROCEDURE or FUNCTION. Note that DCAL has many internal PROCEDURES and FUNCTIONS and you should not use any of their names either.
A PROCEDURE may take parameters (<optional_params>) These parameters are variables that will be used in some way by the PROCEDURE. Your PROCEDURES may declare variables that they need to do their work.
Variables used only in and seen only within a PROCEDURE are called local variables. The use of local variables is optional. The keyword BEGIN tells the compiler here is where the actual work starts.
Finally the PROCEDURE ends with the keyword END followed by the name of the procedure. The name must match at both the PROCEDURE declaration and the END of the PROCEDURE.
The syntax for a FUNCTION is:
A FUNCTION is similar to a PROCEDURE. It must have a unique name <function_name>. It begins with the FUNCTION keyword and ends with the END keyword followed by the name of the FUNCTION. It may declare local variables and it needs the BEGIN keyword before the <statement(s)> section. A FUNCTION may take parameters.
The key difference is that a FUNCTION will return a value. What this means is that a FUNCTION will evaluate to one of DCALs TYPES. A FUNCTION may have multiple RETURN statements in its code however only the first one that is encountered will be executed. Once the program hits a RETURN statement the <return_value> is sent back to the routine that called the FUNCTION and the FUNCTION terminates. The difference between PROCEDURES and FUNCTIONS are subtle but important.