next up previous contents
Next: Using infix operators Up: CHAPTER.2: INTRODUCTION TO Previous: Global and local

Procedure calls in Pop-11

The definition of silly included two imperatives of the form "item =>". These printing instructions are not obeyed at compile time, when Pop-11 reads in the definition. Rather, a procedure is then created in which the instructions are stored for future use (in the same login session - if you leave Poplog and then restart it later, it will not remember your previously compiled procedures, unless you make use of the saved image mechanism, described in HELP SYSSAVE).

So we need a means of telling Pop-11 to actually obey the instructions after they have been compiled.

We also need to tell Pop-11 which object it should give to silly as the `item' to be printed out twice. This is done by writing the name of the procedure, followed by parentheses specifying the inputs (arguments) of the procedure:

    silly([mary had a little lamb]);
Given the above definition of the procedure silly, this would cause the following to be printed out:

    ** [mary had a little lamb]
    ** [mary had a little lamb]
Terminology varies. We may say the compiled procedure is `run', `invoked', `obeyed', `executed', or `applied'. These all mean roughly the same, though some may be more natural in certain contexts. For instance we say the procedure silly was `applied' to the list

    [mary had a little lamb]
Some procedures take no arguments (no inputs). They are run without being applied to anything, though they still need the parentheses after the procedure name to signify that running is required, and not just reference to the procedure itself. One such procedure is the system procedure sysdaytime, which produces a string of information about date and time. We can run it, with no inputs, and use the print arrow to print out the resulting string. Note the empty parentheses signifying that the procedure needs no inputs:

    sysdaytime() =>
    ** Sun Feb 27 11:56:11 GMT 1994
Contrast what happens without the imperatives:

    sysdaytime =>
    ** <procedure sysdaytime>

Imperatives end with separators

Notice that all the imperatives requesting that Pop-11 do something ended with either a semi-colon or a print-arrow. Pop-11 will not start executing the imperative until it finds the semi-colon or the print-arrow, since until then it is not sure whether the imperative is complete or some additional portion is to be added. This is because Pop-11 allows a single command to be spread over several lines. (Individual lines and whole commands can be as long as you like: newlines and spaces are equivalent in Pop-11).



next up previous contents
Next: Using infix operators Up: CHAPTER.2: INTRODUCTION TO Previous: Global and local



Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998