digitalmars.D - pure format
- Oleg B (8/8) Jun 04 2015 Hello. I not found realization of pure format function (in phobos
- Jonathan M Davis (8/17) Jun 04 2015 std.format.format should be pure if its arguments have pure
- Oleg B (16/34) Jun 04 2015 I think toString for float must be pure, but in practice it's not.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/19) Jun 04 2015 Floating point operations share global state ("flags" or "attributes")
- Meta (5/10) Jun 04 2015 That is not it (if it is, it's a bug), as D allows pure functions
- Steven Schveighoffer (9/31) Jun 04 2015 That is a terrible excuse if that is what the issue is.
- Yuxuan Shui (4/14) Jul 01 2015 Is it possible to get this fixed in mainline phobos? Not having a
- HaraldZealot (5/11) Jul 01 2015 And I also remember that format doesn't work in CT, so it was
- Nicholas Wilson (3/17) Jul 02 2015 pretty sure std.metastring(s?) was deprecated 'cos format works
- Dmitry Olshansky (4/19) Jul 02 2015 Yeah, formattedWrite definitely works at CTFE these days.
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.
Jun 04 2015
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
Jun 04 2015
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: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. o_purity_68957.html and if it try it's not a bug...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
Jun 04 2015
On 06/04/2015 10:02 AM, Oleg B wrote: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 sprintfhttp://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv. o_purity_68957.htmland if it try it's not a bug...Floating point operations share global state ("flags" or "attributes") for rounding mode, exception and trap handling. Perhaps that's why floating point format cannot be pure. Ali
Jun 04 2015
On Thursday, 4 June 2015 at 18:08:09 UTC, Ali Çehreli wrote: http://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv.to_purity_68957.htmlThat is not it (if it is, it's a bug), as D allows pure functions to set and check those flags. http://dlang.org/function.html#pure-functionsand if it try it's not a bug...Floating point operations share global state ("flags" or "attributes") for rounding mode, exception and trap handling. Perhaps that's why floating point format cannot be pure. Ali
Jun 04 2015
On 6/4/15 2:08 PM, Ali Çehreli wrote:On 06/04/2015 10:02 AM, Oleg B wrote: > 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... Floating point operations share global state ("flags" or "attributes") for rounding mode, exception and trap handling. Perhaps that's why floating point format cannot be pure.That is a terrible excuse if that is what the issue is. I recalled Don discussing this, found these threads (they are old, maybe something has gotten better since then): http://forum.dlang.org/post/gpddrm$20u7$1 digitalmars.com http://forum.dlang.org/post/h8ad5r$22jj$1 digitalmars.com From that, it does seem that D does not care about the rounding modes, and just considers the code pure. -Steve
Jun 04 2015
On Thursday, 4 June 2015 at 18:27:16 UTC, Steven Schveighoffer wrote:On 6/4/15 2:08 PM, Ali Çehreli wrote:Is it possible to get this fixed in mainline phobos? Not having a pure format() is really annoying.[...]That is a terrible excuse if that is what the issue is. I recalled Don discussing this, found these threads (they are old, maybe something has gotten better since then): http://forum.dlang.org/post/gpddrm$20u7$1 digitalmars.com http://forum.dlang.org/post/h8ad5r$22jj$1 digitalmars.com From that, it does seem that D does not care about the rounding modes, and just considers the code pure. -Steve
Jul 01 2015
On Thursday, 4 June 2015 at 17:02:46 UTC, Oleg B wrote:On Thursday, 4 June 2015 at 16:21:54 UTC, Jonathan M Davis wrote: I think toString for float must be pure, but in practice it's not. It's a bug? I read what std.format.format using libc sprintf http://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv. o_purity_68957.html and if it try it's not a bug...And I also remember that format doesn't work in CT, so it was really uncomfortable that a can't initialize array of special values for algorithm in CT. It was a more than year ago, possible something changes.
Jul 01 2015
On Thursday, 2 July 2015 at 04:41:51 UTC, HaraldZealot wrote:On Thursday, 4 June 2015 at 17:02:46 UTC, Oleg B wrote:pretty sure std.metastring(s?) was deprecated 'cos format works at CTOn Thursday, 4 June 2015 at 16:21:54 UTC, Jonathan M Davis wrote: I think toString for float must be pure, but in practice it's not. It's a bug? I read what std.format.format using libc sprintf http://www.digitalmars.com/d/archives/digitalmars/D/learn/std.conv. o_purity_68957.html and if it try it's not a bug...And I also remember that format doesn't work in CT, so it was really uncomfortable that a can't initialize array of special values for algorithm in CT. It was a more than year ago, possible something changes.
Jul 02 2015
On 02-Jul-2015 12:53, Nicholas Wilson wrote:On Thursday, 2 July 2015 at 04:41:51 UTC, HaraldZealot wrote:Yeah, formattedWrite definitely works at CTFE these days. -- Dmitry OlshanskyOn Thursday, 4 June 2015 at 17:02:46 UTC, Oleg B wrote:pretty sure std.metastring(s?) was deprecated 'cos format works at CTOn Thursday, 4 June 2015 at 16:21:54 UTC, Jonathan M Davis wrote: I think toString for float must be pure, but in practice it's not. 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...And I also remember that format doesn't work in CT, so it was really uncomfortable that a can't initialize array of special values for algorithm in CT. It was a more than year ago, possible something changes.
Jul 02 2015