SYS-PRINT(2) SYS-PRINT(2)
NAME
print, aprint, fprint, sprint - print formatted output
SYNOPSIS
include "sys.m";
sys := load Sys Sys->PATH;
aprint: fn(format: string, *): array of byte;
fprint: fn(fd: ref FD, format: string, *): int;
print: fn(format: string, *): int;
sprint: fn(format: string, *): string;
DESCRIPTION
These functions format and print their arguments as UTF
text. Print writes text to the standard output. Fprint
writes to the named output file descriptor. Sprint places
text in a string, which it returns. Aprint is similar but
returns the text in utf(6) representation as an array of
bytes. Print and fprint return the number of bytes trans-
mitted or a negative value if an error was encountered when
writing the output.
Each of these functions converts, formats, and prints its
trailing arguments under control of a format string. The
format contains two types of objects: plain characters,
which are simply copied to the output stream, and conversion
specifications, each of which results in fetching of zero or
more arguments. The Limbo compiler recognizes calls to
these functions and checks that the arguments match the for-
mat specifications in number and type.
Each conversion specification has the following format:
% [flags] verb
The verb is a single character and each flag is a single
character or a (decimal) numeric string. Up to two numeric
strings may be used; the first is called f1, the second f2.
They can be separated by `.', and if one is present, then f1
and f2 are taken to be zero if missing, otherwise they are
considered `omitted'. Either or both of the numbers may be
replaced with the character *, meaning that the actual num-
ber will be obtained from the argument list as an integer.
The flags and numbers are arguments to the verb described
below.
d, o, x,
The numeric verbs d, o, and x format their int argu-
ments in decimal, octal, and hexadecimal (with hex dig-
its in lower-case). The flag b is required when the
Page 1 Plan 9 (printed 10/27/25)
SYS-PRINT(2) SYS-PRINT(2)
corresponding value is a Limbo big, not an int. Argu-
ments are taken to be signed, unless the u flag is
given, to force them to be treated as unsigned. Each
interprets the flags - , , , and # to mean left justi-
fied, commas every three digits, and alternative for-
mat. If f2 is not omitted, the number is padded on the
left with zeros until at least f2 digits appear. Then,
if alternative format is specified for x conversion,
the number is preceded by 0x. Finally, if f1 is not
omitted, the number is padded on the left (or right, if
left justification is specified) with enough blanks to
make the field at least f1 characters long. The verb X
is similar to x, except that the hexadecimal digits are
displayed in upper-case, and in alternative format, the
number is preceded by 0X.
e, f, g
The floating point verbs e, f, and g take a real argu-
ment. Each interprets the flags +, -, and # to mean
always print a sign, left justified, and alternative
format. F1 is the minimum field width and, if the con-
verted value takes up less than f1 characters, it is
padded on the left (or right, if `left justified') with
spaces. F2 is the number of digits that are converted
after the decimal place for e and f conversions, and f2
is the maximum number of significant digits for g con-
versions. The f verb produces output of the form
[-]
h.stigiddnefernamlmth.stigidtratsfernamlmt
h.2fdnefernamlmth.2ftratsfernamlmt
h)1(hsdnefernamlmth)1(hstratsfernamlmt
h&lmtlt;&4Hgt; h&lmtlt;&4H/gt;
h&lmtlt;&4Hgt; h&lmtlt;&4H/gt;
h,)2(ortni-sysdnefernamlmth,)2(ortni-systratsfernamlmth)2(nepo-sysdnefernamlmth)2(nepo-systratsfernamlmt
h&lmtlt;&4Hgt; h&lmtlt;&4H/gt;