Re: another approach to sprintf (Re: ocaml 2.02 bug: curried printf)

From: John Prevost (prevost@maya.com)
Date: Thu Mar 25 1999 - 21:52:05 MET


To: caml-list@inria.fr
Subject: Re: another approach to sprintf (Re: ocaml 2.02 bug: curried printf)
From: John Prevost <prevost@maya.com>
Date: 25 Mar 1999 15:52:05 -0500
In-Reply-To: Christian Lindig's message of "Thu, 25 Mar 1999 14:29:01 +0100"

Christian Lindig <lindig@ips.cs.tu-bs.de> writes:

> The suggested functional approach to printf has another possible
> drawback: when you want to express all the options like "%5.5f"
> possible in C style printf formatting you need a whole bunch of
> functions. Since OCaml has no overloading a single `float' function
> for floats can not capture them all.

Yes, but you can still get the formatting features you want by having
both formats that take arguments (like "lit") and also higher-order
formats (for example, a format which truncates whatever format it is
given to a specific string length, or a format that right justifies
within a certain length, or etc.)

In fact, the system is more powerful precisely because you can do
things like this to extend the system. Not only can you do %5.5f, you
could also make something to display the float in binary, or to
display the fraction as a vulgar fraction symbol (i.e. ½).

John.



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET