[% setvar title Data: sprintf() with overloaded objects %]
To see what is currently happening visit http://www.perl6.org/
Data: sprintf() with overloaded objects
Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu> Date: 15 Sep 2000 Mailing List: perl6-language-data@perl.org Number: 235 Version: 1 Status: Developing
This RFC proposes a support of sprintf() with overloaded objects;
The problems:
* in the flags.One would want an interface which allows to get acceptable results with a minimal of work, but also allows as fine control as possible if needed. The solution:
'%i' and '%d' should invoke the same overloaded operation
keyed by %d (or %?d, see below).'%+040d' should invoke the operation keyed by
'%?d' if present, otherwise one keyed by '%d', then would postprocess
the results. Similarly, '%d' should invoke the operation keyed by
'%d' if present, otherwise one keyed by '%d'.* is present in the flags, the count is provided as an additional
argument to the corresponding method. (One additional argument per each *.)For example, if method '%d' is overloaded by the method FORMAT_D,
and '%?d' is not overloaded, then
sprintf('%s %0*i %s', '--', $overloaded_object, 10, '--')
calls
$overloaded_object->FORMAT_D('0*i', 10);
and postprocesses the result.
The "standard" semantic of processing flags in the overloaded methods for composite objects (such as complex numbers or vectors) should be: delegate the flags to components "as is". (As opposed to applying widths to the total field.)
There may be obvious exceptions: for complex numbers +/- before the
imaginary part is needed, but if one inserts this sign no matter what,
the format '%+10i' would result in a double + sign or +- or --.
The other approach of prepending '+' to the flags no matter what would
omit space for the format '% 10i'.
NONE
More or less straightforward
RFC ???