Statement: write
The write statement is intended to provide written output.
write Statement | ||
---|---|---|
Format | Example | Output |
write expr; | write "Triangular number T4 = " + (1+2+3+4); | Triangular number T4 = 10 |
write expr, expr; | let a = {: ,5/2,,}; write "Object", a; | Object, {: null, 2.5, null, null} |
write expr nl expr; | write "Well ordered rlist" nl 10..20 & !15; | Well ordered rlist 10..14 | 16..20 |
write.filecode expr; | write.text "Next line in the text file" nl; |
The expr
is a value which is the result of an expression.
It is first evaluated and then "stringified",
or converted into text.
It should be noted the the plus operator '+' is used for both numerical addition and string concatenation. The rule is, if both sides of the operator are numbers, the values are added together. But if one side is a string, the other side is converted to a string and the two concatenated. Since operators of equal precedence are evaluated from left to right, one string to the left of a succession of numbers being added will affect them all. When in doubt, put all calculations in parentheses.
Example | Result |
---|---|
write 5 + 10 + 15; | 30 |
write "" + 5 + 10 + 15; | 51015 |
write "" + 5 + (10 + 15); | 525 |
write !0; | -infinity..-1 | 1..+infinity |
write {: ,10}; | {: null, 10} |
write @load:blob( "glich32.png" ); | blob:png:1999 |
In addition to expressions, the write statement can contain ',' (comma) character and the nl constant. The comma will output the string ", ". The nl value outputs a new line character.
Output
If the write statement has a filecode
qualifier,
the output will be sent to the appropriate file.
Otherwise output is sent to the standard output device.
Exactly how the standard output is displayed will depend upon the program running the script. The glcs interactive terminal program simply outputs the text to the following line. The Gliched editor displays the output in the output window.
Statement: writeln
The writeln statement is the same as the write statement except writeln adds a newline character to the end of the output.
The following two statements are identical:
writeln "some text";
and write "some text" nl;
The second is preferred.
The writeln statement may be removed in a future version.