On Tue, Jan 08, 2013 at 10:54:44PM +0100, Jonathan Worthington wrote: > On 1/8/2013 22:38, Patrick R. Michaud wrote: > > I wonder what it would take to write a version of sprintf in Perl 6 or > > NQP directly, ignoring all speed aspects for the time being. Then we'd > > at least have something portable, provably correct, easily modified, > > and that could be used as a reference implementation. It also might > > give some pointers on what can be done to ultimately deal with speed > > issues. > This is my preference, for what it's worth. It would also fix the > sprintf of big integer issues we currently have, and be a win for porting.
I think that the right way to go is to write sprintf, or as much of it as is possible, in NQP. Specifically, I suspect that all the parsing of the % codes should be done in high level language, only kicking down to something lower level for the actual formatting (and probably even then, only for the floating point formatting, and maybe optimised versions for the most common cases for decimals.) It's going to end up being a) faster to write b) easier to maintain c) easier to port d) possible to optimise in ways that just can't be done via a monolithic call. For an example, see this PyPy blog entry: http://morepypy.blogspot.com/2011/08/pypy-is-faster-than-c-again-string.html Nicholas Clark