printf is useful in defining print methods, either with class_print
or in lib objectclass. For example:
define:objectclass Resistor;
r = 1000;
p = 0.25;
enddefine;
define:method print_object(R:Resistor);
printf('Resistor r = %p ohms, p = %p watts',datalist(R));
enddefine;
However, for printing complicated thingies with this approach, it
would be nice if printf would support indented newlines, where the
indentation count could be cumulative. For example, if one
put the fields of the resistor on new lines:
define:method print_object(R:Resistor);
printf('Resistor \n r = %p ohms, \n p = %p watts',datalist(R));
enddefine;
and try to print an object which includes a resistor indenting the
resistor itself, then the new lines for the fields of the resistor
would not be properly indented. How about %n<d> being
a form which would print a newline in printf, indenting by <d>. Thus
define:method print_object(R:Resistor);
printf('Resistor %n4 r = %p ohms, %n4 p = %p watts',datalist(R));
enddefine;
would print the resistor with the fields indented 4 spaces.
|