Tom Cole - 2009-03-24

I’ve added local subroutines to the language, which are declared in a program using the SUB keyword, similar to BASIC extensions in other languages.  A SUB routine is declared using the same statement syntax as a program or function, but is not stored as a separate program object.

Only the program that contains the SUB routine can call it.  If there is a SUB entry point with a given name that is the same as a program or function, the local version will be the one actually called.

A SUB routine can be called as a function or as a procedure.  If called as a function, it must return a value or an error occurs.  The $MODE variable is set to the word “FUNCTION” or “CALL” depending on the mode in which it was invoked, so the SUB routine can determine for itself how it should return data, if at all.

In the example above, not that program execution doesn’t flow from the PRINT statement to the SUB statement; there is an implicit END before each SUB statement that terminates execution if the program flow hits the SUB statement as a next statement to run.