User-Defined and System Functions: an Overview
User-defined functions may be built to perform certain utilities. These may be a convenient
alternative to writing programs if the job is simple. They have this advantage over
programs: they return objects of the type you specify. Suppose for example
that you want to create an object of 2 dimensional vector type using a program. You might write a program Myprog with a single argument
whose return value is such a vector. But the compiler will not know that the
value of Myprog(x) is a vector. Thus, you may write a function, say Myfun and declare in the
definition that its return type will be a 2 dimensional vector, in the following
way: Make function myfun of type ve #0 (x) Myprog(x); This "wraps a function around a program" and guarantees that the compiler
will get it right.
The System
Functions are functions in the usual sense.
They may accept arguments and they always return values. Typically, they are not
used to do mathematical calculations, however. Sometimes their job is to monitor
the state of the current package or of the current document. For example, getpenwidth()
is a function that returns the penwidth of the pen in the currently selected graphics
window. Notice that getpenwidth(), like many of the functions in this class actually
takes no arguments. Other system functions are used for creating and manipulating
list structures. For example, append(list1, list2) creates a new list from
the argument lists: list1 and list2.