Use the operator << to print something to the screen.
i1 : << 2^100 |
Notice that the value returned is the standard input output file stdio. We can also use << as a binary operator to print explicitly to this file, and the output will appear on the screen.
i2 : stdio << 2^100 |
The associativity of the operator << during parsing is arranged so that the following code will work in a useful way.
i3 : << "The answer is " << 2^100 << "."; |
Printing works fine with nets, too.
i4 : << "The answer is " << "aaa"||"bb"||"c" << "."; |
In the presence of nets, which are used whenever you print something that is formatted two-dimensionally, the only correct way to terminate a line is with endl, even though a string called newline is available to you.
i5 : R = ZZ[x,y]; |
i6 : f = (x+y+1)^2; g = (x-y+1)^2 |
i8 : << "f = " << f << endl << "g = " << g << endl; |
Output is saved in a buffer until the end of the line is encountered. If nets are not involved, you may use flush to force the output to appear on the screen before the end of the line is encountered. This may be useful in displaying some tiny indication of computational progress to the user.
i9 : scan(0 .. 20, i -> << "." << flush) |
If long lines get displayed too slowly, such as in emacs, then the user may choose to put a line such as truncateOutput 100 into an initialization file. Time is still spent creating the wide output which is eventually truncated.
i10 : truncateOutput 50 |
i11 : 41! |
i12 : 42! |
i13 : 43! |
i14 : truncateOutput infinity |
i15 : 43! |