Amos Professional Manual  Contents  Index

Procedures


A procedure is a component of a computer program that allows the AMOS Professional programmer to tackle one aspect of the program at a time, without becoming distracted or side-tracked by other programming considerations. Procedures can be thought of as programming modules, each with a specific purpose and sphere of operation. This Chapter explains how procedures are created and fully exploited.

Creating a procedure

PROCEDURE
structure: create a procedure
Procedure NAME [list of optional parameters]

END PROC
structure: end a procedure
End Proc

A procedure is created in exactly the same way as a normal variable, by giving it a name. The name is then followed by a list of parameters and the procedure must be ended with an END PROC command. PROCEDURE and END PROC commands must be placed on their own individual lines. For example:

E> Procedure HELLO
   Print "Hello, I am a procedure!"
   End Proc

If you try and run that program, nothing will happen. This is because a procedure must be called up by name from inside your program before it can do anything. Now add the following line at the start of that last example, and then [Run] it.

E> HELLO

There is nothing preventing a procedure from calling itself, but this recursion is limited by the area of storage allocated for local variables. If this local variable space is full, it can be increased using the SET BUFFER command. Programs can also be held up if there is no more stack space available, and this problem is cured by the following command.

SET STACK
instruction: set stack space
Set Stack number

When AMOS Professional procedures call themselves, an "Out of stack space" error message will be generated after about fifty loops. Use the SET STACK instruction by specifying the new number of procedure calls that an be made.

Keeping track of procedures
To help you find the starting positions of procedures in a very long program, there is a simple short-cut that uses just two keys.

Back    Next
05.05.01