Function arguments

Sometimes you may want to design routines which takes as its first argument a function as an argument.

Currently, such functions are placed in the module according to the type of argument the function returns, and these arguments are marked as [routinal]. What that means is that the first argument is not assumed to be of the type contained inthe module, but must be specified manually, say by an interface specification. For an example, see the minimise_brent routine in the REAL module.

Usually, such routinals are used in conjunction with a routine with the [selfless] attribute. Selfless routines are those whose first argument is not the self argument of type contained in the module. Instead, the self variable is set at the first line of the selfless routine to be equal to a saved_self variable which is globally visible within the module. In this was, a selfless routine can be passed to a routinal (typically a minimiser) which then calls the passed routine during the course of its execution. The called selfless routine can have access to the current self variable. In this way, a function and some of its arguments can be passed to a minimiser. In some languages this is called "closure". For an example, see the chi2 selfless routine in the CRSYTAL module.

Compilers are not often able to cope with this mechanism, so unfortunately, it is rarely used.

Currently, there is no convention in TONTO on which module to place routines which take subroutines as their first argument. Such routines are not encountered in TONTO.