conv text and pure

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


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). Furthermore, to!string(S) for
some struct S appears to be impure by default unless you manually define
a toString method that declares itself pure. Unfortunately,
to!string(DateTime.init) isn't pure either, which means that if your
struct contains DateTime and you need to format it then you're out of
luck.

So basically, text() is still practically unusable for anything that
isn't already trivially convertible to string (like string itself). Or
int -- apparently to!string(int.init) does work in pure code.

IOW, the purity of text() and to() still has a long ways to go before
user code can depend on it. :-(

Please file a bug in the bugtracker.

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.


T

-- 
I am Ohm of Borg. Resistance is voltage over current.


More information about the Digitalmars-d-learn mailing list