The normal interaction with GAP happens in the so--called read eval print loop. This means that you type an input, GAP first reads it, evaluates it, and prints the result. The exact sequence is as follows.
To show you that it is ready to accept your input, GAP displays the
gap . When you see this, you know that GAP is waiting for
Note that every statement must be terminated by a semicolon. You must also enter return before GAP starts to read and evaluate your input. Because GAP does not do anything until you enter return, you can edit your input to fix typos and only when everything is correct enter return and have GAP take a look at it (see Line Editing). It is also possible to enter several statements as input on a single line. Of course each statement must be terminated by a semicolon.
It is absolutely acceptable to enter a single statement on several lines.
When you have entered the beginning of a statement, but the statement is
not yet complete, and you enter return, GAP will display the
; that terminates every GAP statement.
When you enter return, GAP first checks your input to see if it is syntactically correct (see chapter The Programming Language for the definition of syntactically correct). If it is not, GAP prints an error message of the following form
gap> 1 * ; Syntax error: expression expected 1 * ; ^
The first line tells you what is wrong about the input, in this case the
* operator takes two expressions as operands, so obviously the right
one is missing. If the input came from a file (see Read), this line
will also contain the filename and the line number. The second line is a
copy of the input. And the third line contains a caret pointing to the
place in the previous line where GAP realized that something is wrong.
This need not be the exact place where the error is, but it is usually
Sometimes, you will also see a partial prompt after you have entered an
input that is syntactically incorrect. This is because GAP is so
confused by your input, that it thinks that there is still something to
follow. In this case you should enter
;return repeatedly, ignoring
further error messages, until you see the full prompt again. When you
see the full prompt, you know that GAP forgave you and is now ready to
accept your next -- hopefully correct -- input.
If your input is syntactically correct, GAP evaluates or executes it, The Programming Language for the definition of the evaluation).
If you do not see a prompt, you know that GAP is still working on your last input. Of course, you can type ahead, i.e., already start entering new input, but it will not be accepted by GAP until GAP has completed the ongoing computation.
When GAP is ready it will usually print the result of the computation,
i.e., the value computed. Note that not all statements produce a value,
for example, if you enter a
for loop, nothing will be printed, because
for loop does not produce a value that could be printed.
Also sometimes you do not want to see the result. For example if you have computed a value and now want to assign the result to a variable, you probably do not want to see the value again. You can terminate statements by two semicolons to suppress the printing of the result.
If you have entered several statements on a single line GAP will first read, evaluate, and print the first one, then read evaluate, and print the second one, and so on. This means that the second statement will not even be checked for syntactical correctness until GAP has completed the first computation.
After the result has been printed GAP will display another prompt, and wait for your next input. And the whole process starts all over again. Note that a new prompt will only be printed after GAP has read, evaluated, and printed the last statement if you have entered several statements on a single line.
In each statement that you enter the result of the previous statement
that produced a value is available in the variable
last. The next to
previous result is available in
last2 and the result produced before
that is available in
gap> 1; 2; 3; 1 2 3 gap> last3 + last2 * last; 7
Also in each statement the time spent by the last statement, whether it
produced a value or not, is available in the variable
time. This is an
integer that holds the number of milliseconds.
Up Top Next