conv text and pure

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Oct 24 11:57:33 PDT 2013


On Thu, Oct 24, 2013 at 11:36:09AM -0700, H. S. Teoh wrote:
> On Thu, Oct 24, 2013 at 12:12:48AM +0200, Daniel Davidson wrote:
> [...]
> > Here is the self-contained code (I hope) that you can see it
> > happening in:
> > http://pastebin.com/hb0Dz50r
> [...]
> 
> Hmm. Somebody claimed that 2.064 beta has made text() pure, but that's
> only partially true, because it calls to!(), and so its purity depends
> on the purity of to!().  Unfortunately, to!() is NOT pure for many basic
> types, including to!string(double.init).
[...]
> In the meantime, I'm going to track down exactly why to!string(double)
> isn't pure, since there's no valid reason why it can't be.
[...]

So I traced the code down in Phobos, and discovered that the reason
to!string(double.init) isn't pure is because it ultimately calls the C
library snprintf to format floating-point values.

And the fact that it uses toString(scope void delegate(const(char)[])),
which can't be made pure because its purity depends on the purity of the
delegate, and currently the compiler has no way of inferring this, and
the language has no way to express this. :-(

Which means unless we rewrite large swaths of std.conv, making
text(double.init) pure isn't going to happen anytime soon. :-(


T

-- 
It is not the employer who pays the wages. Employers only handle the
money. It is the customer who pays the wages. -- Henry Ford


More information about the Digitalmars-d-learn mailing list