Tutorial - Program Parameters

Command Line Parameters

When invoking a grarls program it is possible to pass command line parameters to it. Command line parameters consist of two types "system parameters" and "program parameters".

A typical program invocation has the following form :-

        grarls [ system_parms ] prog_name [ program_parms ]

In this tutorial we will concentrate on the program parameters. These are optional and always follow the filename of the program being invoked.

When you have defined your Program routines in previous tutorials you have always left the parameter list blank. You can actually specify parameters in the same way for any other routine - although there are restrictions on the types that can be used ( just Number, Logical, Text and Enum types ).

Consider the following program :-

Program(Text message, Logical option, Number n)
    Begin
	Output message, option, n;
    End;

This should be invoked with a command line of the form :-

  grarls progparms.grs "Hello" True 42 

Enumerated Type Parameters

Any enumerated type defined in the program can also be used for parameters.

Consider the following program :-

Type Season = ( Spring = 1, Summer = 2, Autumn = 3 = "Fall", Winter = 4 );
Program(Season s)
    Begin
	Output s;
    End;

This could be invoked with any of the following, with the expected result :-

  grarls progparms.grs Spring
  grarls progparms.grs 2
  grarls progparms.grs Fall

Note: in the above I have explicitly specified the numeric indexes for the Season type. This is not necessary but useful to make the program self documenting.

If a required parameters is missing from the command line the value will be set to null - unless the parameter has a default, in which case the default will be used.

If a parameters is invalid then the system will report an error and the program will not be executed.