The Lpp printing functions emulate Common Lisp printing functions in that there are two ways to print Lpp objects to C++ streams, with or without escape characters. All Lpp objects automatically get two type dispatching printing functions for doing this. The user can redefine these dispatching functions if need be, See Accessing Type Meta-Objects.
|prin1 object stream||Function|
|princ object stream||Function|
|print object stream||Function|
All of these functions print the Lpp object object to the C++
output stream stream. If stream is omitted
is assumed. All of these functions return object as its value.
prin1 escape characters are used as appropriate while
princ prints object with no escape characters. Roughly
speaking the output of
prin1 is suitable for
the output of
princ is intended to look good to people.
prin1 except that the printed
representation of object is preceded with a newline and
followed by a space. Some examples will make this clear, the
let obj = L("one two three"); prin1(obj); print(object); princ(obj);
would produce on
"one two three" "one two three" one two three
Note that the last output produced by
princ when read back
read would produce the Symbol
one instead of the
String "one two three".
C++ output stream operators for Lpp objects default to using
princ so that the following code
let obj = L("one two three"); cout << "Object = " << obj << endl;
would produce on
Object = one two three
O macro allows the Lpp object argument object when
using C++ output stream operators to print using
Contrast the following code and results using the
O macro with
the previous example
let obj = L("one two three"); cout << "Object = " << O(obj) << endl;
would produce on
Object = "one two three"
Note that it only makes sense to use the
O macro with C++
stream operators. The results of using the
O macro elsewhere
terpri outputs a newline to the C++ output stream
stream. If the stream argument is omitted
finishOutput attempts to ensure that all output sent to the C++
output stream stream has reached its destination and only then
nil. If the stream argument is omitted
cout is assumed.
|pprint object stream||Function|
|pprint object stream start end||Function|
pprint is just like
cout is assumed. If the start and end
arguments are included the output will be pretty printed between
columns start and end. start and end must
ints. All of these functions return object as its
Pretty means that the object is printed using extra white space to make it easily human readable. For example nested lists are indented to make the tree structure apparent.
Both of these functions return an Lpp String with the printed
representation of object.
prin1ToString returns the
prin1 printed representation.
princToString returns the
princ printed representation. For example:
let obj = prin1ToString(list(L(1), L(2), L(3))); prin1(obj) => "(1 2 3)"
princToString are used to
print relatively short expressions or values to strings. The maximum
length of such a string allowed by default is 4096 characters which is
determined by the define variable LPP_PRINTOSTRING_MAX. If more
characters are desired for some reason redefine LPP_PRINTOSTRING_MAX
to a value bigger than 4096 before the include file
the Lpp library compile stream.
prin1Length returns as an
representation length of the Lpp object object.
prin1LengthL does the same but returns the length as an Lpp
princLengthL are the
princ. Here are some examples:
prin1Length(S(hello)) => 5 prin1Length(L("hello")) => 7 princLength(L("hello")) => 5 prin1Length(L(-1234)) => 5 prin1Length(list(L(1), L(2))) => 5