Next: , Previous: , Up: Statements   [Contents][Index]


7.13 Subroutine Call

A subroutine is a named "black box" that performs a specific task, depending on the values that are specified for the subroutine’s parameters, if any, and possibly on the values of some global variables (Global Variables).

name [, arg1, arg2 … ]

calls the subroutine that has name name, with the listed arguments, separated by commas. A subroutine call need not have any arguments. See Arguments to learn more about the various ways in which arguments can be specified for subroutines.

LUX offers many internal subroutines (Internal Routines), and also allows the user to define subroutines written in the LUX language (Subroutine Definition).

Because internal subroutines, user-defined subroutines, and subroutine pointer variables (Pointers) all have their own name spaces, symbols of these three kinds can exist at the same time even if they all have the same name. For instance, in addition to the internal subroutine called limits (limits), one can also have a subroutine pointer named limits and a user-defined subroutine named limits, all at the same time (remember that upper case and lower case letters are equivalent in this situation).

Which of these three possibilities is to be executed is determined at compile time, as described below. The first match (at the time that the statement is compiled) is taken.

  1. If the subroutine symbol is a pointer (Pointers) to an internal or (possibly not yet compiled) user-defined subroutine, then that subroutine is taken.
  2. If a user-defined subroutine exists with the indicated name, then that subroutine is taken.
  3. If an internal subroutine exists with the indicated name, then that subroutine is taken.
  4. Otherwise, a user-defined subroutine with the indicated name is assumed to become available, and that subroutine is taken.

If during execution a user-defined subroutine turns out not to have been compiled yet, then LUX tries to find a file that contains a definition for that subroutine. LUX looks for a file with the same name as the subroutine, transformed to all lower-case letters, and with the .lux suffix added. LUX looks for this file in the directories which are listed, separated by colons (:) in the environment variable LUX_PATH (Environment), and in the directory, if any, that was specified using ulib (ulib). If such a file is found, then it is included at this point. If the sought subroutine is still not defined after the file has been included, then an error message is displayed.

The way of linking a subroutine symbol to a particular subroutine at compile time allows various kinds of shadowing, of hiding a particular subroutine behind some other one. E.g., you can hide the internal definition for limits by defining your own version (Subroutine Definition), or by creating a pointer with that same name that points at a subroutine of your choice, and you can hide a user-defined subroutine named mycode by defining a pointer with that same name that points at another subroutine. The hidden definitions are not deleted; they are merely hidden and can be restored as first choice by deleting the overlaid definitions.

Subroutines can be called recursively. See Recursion for details.

Some subroutines can be called with more arguments than it has parameters. See Extended Parameter Lists for details.


Next: , Previous: , Up: Statements   [Contents][Index]