Re: 'pp' for D?

2013-10-01 Thread linkrope
On Tuesday, 1 October 2013 at 07:30:06 UTC, Jacob Carlborg wrote: On 2013-09-30 23:56, bearophile wrote: Surely Phobos should add a prettyPrinting() function, like the function of Python standard library. I would rather have function that generates a pretty representation of a given value.

Re: 'pp' for D?

2013-09-30 Thread linkrope
On Monday, 30 September 2013 at 04:20:32 UTC, Ali Çehreli wrote: I don't know a Phobos function either but the following should work: import std.stdio; import std.traits; void pp(T)(File output, T value) { static if (isSomeString!T) { output.writef(`"%s"`, value); } else {

Re: 'pp' for D?

2013-09-29 Thread linkrope
On Sunday, 29 September 2013 at 18:14:03 UTC, monarch_dodra wrote: On Sunday, 29 September 2013 at 14:31:15 UTC, linkrope wrote: As a workaround, I put the value into an array to make use of the "undocumented" function formatElement: "%(%s%)".format([value]) That s

'pp' for D?

2013-09-29 Thread linkrope
I want to pretty-print the representation of a value of a generic type T. In Ruby, I would use 'pp': value = 'hello' pp value # prints "hello" - with quotes! value = 42 pp value # prints 42 Now, value.to!string eliminates the quotes, should value be of type string. As a worka