digitalmars.D.learn - format()
- Lloyd Dupont (3/3) Jun 12 2011 Apparently std.string.format() is not implemented / does not compile! :(
- bearophile (10/11) Jun 12 2011 This works for me, DMD 2.053:
- Lloyd Dupont (5/6) Jun 12 2011 mm... ok.
- David Nadlinger (4/7) Jun 12 2011 Because format presumably can't be interpreted at compile time (yet) –...
- Jonathan M Davis (14/22) Jun 12 2011 Yeah. format can only be used at runtime. If you want a version which wo...
- Lloyd Dupont (15/22) Jun 12 2011 yep, the example is simple because it is an example!
- jdrewsen (6/9) Jun 12 2011 Because the mixin is evaluated at compile time. This means that
Apparently std.string.format() is not implemented / does not compile! :( Is there any sort of replacement? Something which works like writefln() but output a string!
Jun 12 2011
Lloyd Dupon:Apparently std.string.format() is not implemented / does not compile! :(This works for me, DMD 2.053: import std.stdio, std.string; void main() { int x = 10; auto s = format("%d", 10); writeln(">", s, "<"); } Bye, bearophile
Jun 12 2011
mm... ok. but why the line below doesn't compile? mixin(format("class %s {}", "A")); "bearophile" wrote in message news:it2pf5$1qh6$1 digitalmars.com...Apparently std.string.format() is not implemented / does not compile! :(This works for me, DMD 2.053:
Jun 12 2011
On 6/12/11 6:37 PM, Lloyd Dupont wrote:mm... ok. but why the line below doesn't compile? mixin(format("class %s {}", "A"));Because format presumably can't be interpreted at compile time (yet) – not all functions are necessarily CTFEable. David
Jun 12 2011
On 2011-06-12 10:30, David Nadlinger wrote:On 6/12/11 6:37 PM, Lloyd Dupont wrote:=80=93mm... ok. but why the line below doesn't compile? =20 mixin(format("class %s {}", "A"));=20 Because format presumably can't be interpreted at compile time (yet) =E2=not all functions are necessarily CTFEable.Yeah. format can only be used at runtime. If you want a version which works= at=20 compile time, then you std.metastrings.Format, which is an eponymous templa= te.=20 e.g. mixin(Format!("class %s {}", "A")); should work. Of course, in this particular case, you might as well just giv= e=20 the whole string to the mixin directly, but I assume that the example is so= =20 simple simply because it's an example. =2D Jonathan M Davis
Jun 12 2011
yep, the example is simple because it is an example! Thanks for your suggestion! :) "Jonathan M Davis" wrote in message news:mailman.850.1307909499.14074.digitalmars-d-learn puremagic.com... On 2011-06-12 10:30, David Nadlinger wrote:On 6/12/11 6:37 PM, Lloyd Dupont wrote:Yeah. format can only be used at runtime. If you want a version which works at compile time, then you std.metastrings.Format, which is an eponymous template. e.g. mixin(Format!("class %s {}", "A")); should work. Of course, in this particular case, you might as well just give the whole string to the mixin directly, but I assume that the example is so simple simply because it's an example. - Jonathan M Davismm... ok. but why the line below doesn't compile? mixin(format("class %s {}", "A"));Because format presumably can't be interpreted at compile time (yet) – not all functions are necessarily CTFEable.
Jun 12 2011
Den 12-06-2011 18:37, Lloyd Dupont skrev:mm... ok. but why the line below doesn't compile? mixin(format("class %s {}", "A"));Because the mixin is evaluated at compile time. This means that format(...) is evaluated at compile time which afaik is not supported. It may be supported in the future with the improved CTFE that is being worked on. /Jonas
Jun 12 2011