Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
The print statement provides a simple way of displaying (to Glish's stdout) values. Its syntax is:
print value1, value2, ...where any number of values may be listed (including none, which produces a blank line).
By default, large amounts of output are sent through a pager, e.g. less
or more. This prevents the information from being overwhelming.
The pager to be run is determined by system.output.pager.exec
.
The line limit where paging starts is determined by
system.output.pager.limit
. Setting the limit to 0 causes the
pager to always be used, and setting the limit to -1 causes it to never be
used.
At the moment printing of values is crude. Values are printed with a single blank between them and a final newline added at the end. There are only two ways of affecting the printing of Glish values. These can be used either as an attribute of a given value or specified for the whole system.
print.precision
. It is sometimes important to increase
the number of decimal precision used to print floating point
values. This method sets
the number of significant digits that are used to
display floating point numbers.
If this is set in the system record, then the default output
behavior changes for the entire system:
a := 142.8767901343 print a system.print.precision := 10 print aIn this example, the precision is initially set to 6 but is changed to 10 before the second print statement, therefore the output looks something like:
142.877 142.8767901Note that this sets the number of significant digits not the number of decimal places. The print precision can also be set for individual values by setting attributes of the value. In this case, it only affects how this single value is printed. Continuing the example above:
Pi := 3.141592653589793238462643 print Pi Pi::print.precision := 15 print Pi print aThe output this time will look like:
3.141592654 3.14159265358979 142.8767901This provides a very basic way of controlling the output precision of floating point numbers. Setting precision to a negative integer resets the default printing behavior for both system and attribute.
print.limit
. This is used to avoid inadvertently
printing very large values to the screen. For example:
a := 1:1e7 # print a # this would be a mistake! a::print.limit := 10 print aBy setting the print limit for a you get this output:
[1 2 3 4 5 6 7 8 9 10 ... ]instead of many pages of integers. As with
print.precision
, this can be set in system record to
change the default print limit for the whole system, or it can be
specified as an attribute of any value to change the limit for that
value only. Setting limit to be 0
or a negative integer resets things to the default limit, i.e. no print
limit.
In the future print must be extended to allow more sophisticated formatting.