### 2.3.3 Procedures and libraries

SINGULAR offers a comfortable programming language, with a syntax close to C. So it is possible to define procedures which bind a sequence of several commands in a new one. Procedures are defined using the keyword `proc` followed by a name and an optional parameter list with specified types. Finally, a procedure may return a value using the command `return`.

We may e.g. define the following procedure called `Milnor`: (Here the parameter list is `(poly h)` meaning that `Milnor` must be called with one argument which can be assigned to the type `poly` and is referred to by the name `h`.)

    proc Milnor (poly h)
    {
      return(vdim(groebner(jacob(h))));
    }

Note: if you have entered the first line of the procedure and pressed `RETURN`, SINGULAR prints the prompt `.` (dot) instead of the usual prompt `>` . This shows that the input is incomplete and SINGULAR expects more lines. After typing the closing curly bracket, SINGULAR prints the usual prompt indicating that the input is now complete.

Then we can call the procedure:

    Milnor(f);
    ==> 12

Note that the result may depend on the basering as we will see in the next chapter.

The distribution of SINGULAR contains several libraries, each of which is a collection of useful procedures based on the kernel commands, which extend the functionality of SINGULAR. The command `listvar(package);` list all currently loaded libraries. The command `LIB "all.lib";` loads all libraries.

One of these libraries is `sing.lib` which already contains a procedure called `milnor` to calculate the Milnor number not only for hypersurfaces but more generally for complete intersection singularities.

Libraries are loaded using the command `LIB`. Some additional information during the process of loading is displayed on the screen, which we omit here.

    LIB "sing.lib";

As all input in SINGULAR is case sensitive, there is no conflict with the previously defined procedure `Milnor`, but the result is the same.

    milnor(f);
    ==> 12

The procedures in a library have a help part which is displayed by typing

    help milnor;

as well as some examples, which are executed by

    example milnor;

Likewise, the library itself has a help part, to show a list of all the functions available for the user which are contained in the library.

    help sing.lib;

The output of the help commands is omitted here.

User manual for Singular version 4.4.1, 2025, generated by texi2html.