The print statement provides a simple way of displaying (to Glish's stdout) values. Its syntax is:
print value, value,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
and the line limit where paging starts is determined by
system.output.pager.limit. Setting the limit to 0 will cause the
pager to always be used, and setting it to -1 will cause it to never be
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 only two ways of affecting the printing of Glish values. These can be either be used as an attribute to a given value or specified for the whole system.
The first is
print.precision. Sometimes it is important to increase
the amount of decimal precision used to print floating point values. This sets
the number of significant digits which are used to display floating point numbers.
If this is set in the system record, then the default output behavior is
changed for the entire system:
a := 142.8767901343 print a system.print.precision := 10 print aIn this example, the precision is set to 7. The output would look 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 would 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.
The second is
print.limit. This is used to avoid inadvertently
printing very large values to the screen. This again can be
specified as part of the system record to change the default
print limit for the system, or it can be specified as an attribute
of any value. So for example:
a := 1:1e7 # print a # this would be a mistake! a::print.limit := 10 print aBy setting the print limit for a we would get this output:
[1 2 3 4 5 6 7 8 9 10 ... ]instead of many pages of integers. As with
print.precisionthis can also be set in system to change the limit for the whole system. 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.