[% setvar title Data: sprintf() with overloaded objects %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/

TITLE

Data: sprintf() with overloaded objects

VERSION

  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

ABSTRACT

This RFC proposes a support of sprintf() with overloaded objects;

DESCRIPTION

The problems:

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:

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.

Composite objects

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'.

MIGRATION ISSUES

NONE

IMPLEMENTATION

More or less straightforward

REFERENCES

RFC ???