[GOODIE][ENH] Printf

David N. Smith (IBM) dnsmith at watson.ibm.com
Thu Jun 8 18:28:40 UTC 2000


At 0:34 -0700 6/8/00, Michael Rueger wrote:
>Hi all,
>
>talking about C like syntax... ;-)
>
>Attached is a change set which pretty closely emulates string formatting
>based on C's printf function. It's really handy for creating those
>right/left justified fixed width (string,number,hex) strings etc.
>
>The implementation is basically a port of a version I did in ObjectWorks
>a few years ago, which might have introduced a few (new) bugs.
>
>Enjoy
>
>Michael

That looks like a nice bit of work, Michael.

Just for the record, I did a formatter for IBM Smalltalk which I ported to Squeak and is available, with documentation and examples at:

	http://www.dnsmith.com/squeak/formatter.html

It takes a completely different approach, pushing the format items out to the classes which correspond to the kind of data being formatted. That is, Float knows the format items for floats, and Date knows the format items for date. Among other things, this makes it easier to add new format items for a new class, or to enhance formatting for an existing class, and one cannot pass the wrong 'data type'.

Since the release pointed to above, I've fixed a few bugs and added font and color support (using text streams); I'm using it but they are not ready for release quite yet.

One drawback is that the formatter is rich with function and is larger than your printf.  Another is that I had to drop the fancy floating-point support for the first release, but it's coming in the next release (in the fall).

Dave
_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author  
and not of his employer.





More information about the Squeak-dev mailing list