Re: RFC 180 (v1) Object Class hooks into C<printf>
[email protected] ("Mark A. Biggar") Thu, 31 Aug 2000 09:23:45 -0700
| Newsgroups | perl.perl6.language.io |
|---|---|
| Organization | TRusted Systems Laboratories |
| Message-ID | <[email protected]> |
Hildo Biersma wrote: > > > =head1 ABSTRACT > > > > There needs to be a way for an object class to define C<printf> format > > specifiers for use in formatting objects into strings with C<printf> and > > C<sprintf>. > > I find myself agreeing with your sentiment, but the approach in this RFC > is not sufficiently general. Why only provide hooks for printf, not for > formats and output disciplines? > > I think a better approach would be that the to-string operator for > objects should get an optional 'width' parameter. In normal cases > (stringification, interpolation), that argument would not be set. In > printf and formats, but maybe also by specific file disciplines (e.g. > the 72-character-wide output file), the width parameter would be set and > indicate how wide the object may print its data. Thanks you, I had forgot about formats. Note that more then just width information is needed in the general case (and I should add more examples to the RFC to show this). Take the set of printf specifiers that would be needed for the Math::BigFloat package. You would want to define %f, %e and %g at least with all the decimal point placement, padding and sign stuff. Even formats allow for 'basic print using' picture like fields (which I believe get turned into printf specifiers internally) that have more information then just width. In addition I intended that arbitrary object classes could define unique to the class printf specifiers that contain anything the writer wants to define between the % and the final letter. I will write a second version of the RFC over the weekend to address these issues. -- Mark Biggar [email protected]