13. Format
A numeric table such as:
]t=:(i.4 5)%3 0 0.333333 0.666667 1 1.33333 1.66667 2 2.33333 2.66667 3 3.33333 3.66667 4 4.33333 4.66667 5 5.33333 5.66667 6 6.33333
can be rendered more readable by formatting it to appear
with a specified width for each column, and with a specified
number of digits following the decimal point. For example:
]f=: 6j2 ": t 0.00 0.33 0.67 1.00 1.33 1.67 2.00 2.33 2.67 3.00 3.33 3.67 4.00 4.33 4.67 5.00 5.33 5.67 6.00 6.33
The real part of the left argument of the format
function specifies the column width, and the imaginary
part specifies the number of digits to follow the decimal point.
Although the formatted table looks much like the original
table t , it is a table of characters,
not of numbers. For example:
$t 4 5 $f 4 30 +/t 10 11.3333 12.6667 14 15.3333 +/f |domain error | +/f
However, the verb do or execute
(".) applied to such a character table
yields a corresponding numeric table:
". f 0 0.33 0.67 1 1.33 1.67 2 2.33 2.67 3 3.33 3.67 4 4.33 4.67 5 5.33 5.67 6 6.33 +/ ". f 10 11.33 12.67 14 15.33
Exercises
13.1 | Using the programs defined in Section 12, experiment with the following expressions: 5j2 ": d=: %: i.12 5j2 ":,.d fc=: 5j2&":@,. fc d 20 (fc@h3 ,. h5) d 20 (fc@h3 ,. '|'&,.@h5) d plot=: fc@h3,.'|'&,.@h5 20 plot d |