On Thursday, 4 June 2015 at 16:21:54 UTC, Jonathan M Davis wrote:
On Thursday, 4 June 2015 at 14:33:39 UTC, Oleg B wrote:
Hello. I not found realization of pure format function (in
phobos it not pure) and write minimal custom realization.
https://github.com/dexset/desstdx/blob/master/source/des/stdx/pformat.d#L472
Now it works with numbers and strings, but in future I improve
it.
Maybe my realization can help someone =)
Contained in the dub package
http://code.dlang.org/packages/desstdx
If pure format exists tell about it, please.
std.format.format should be pure if its arguments have pure
toString methods or are built-in types. There may be
implementation issues preventing it for one reason or another
(I don't know), but if so, then that's a bug that needs to be
fixed. Regardless, there should be no need for a separate
format function which is pure.
- Jonathan M Davis
I think toString for float must be pure, but in practice it's not.
import std.stdio;
import std.string;
string test( float abc ) pure { return format( "abc: % 6.3f", abc
); }
void main() { writeln( test( 13.3 ) ); }
$ rdmd purefmtfloating.d
purefmtfloating.d(3): Error: pure function 'purefmtfloating.test'
cannot call impure function 'std.format.format!(char,
float).format'
Failed: ["dmd", "-v", "-o-", "purefmtfloating.d", "-I."]
DMD64 v2.067.1
It's a bug? I read what std.format.format using libc sprintf
http://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv.to_purity_68957.html
and if it try it's not a bug...