'pp' for D?
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Tue Oct 1 19:07:54 PDT 2013
On Sun, 29 Sep 2013 16:31:14 +0200
"linkrope" <linkrope at github.com> wrote:
> 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 workaround, I put the value into an array to make use of the
> "undocumented" function formatElement:
>
> "%(%s%)".format([value])
>
> Ugly! Where does Phobos hide the function I'm looking for?
How 'bout either of these?:
void pp(T)(T value) {
writefln("%(%s%)", [value]);
}
string prettyVal(T)(T value) {
return "%(%s%)".format([value]);
}
pp(...whatever...);
string s = prettyVal(...whatever...);
More information about the Digitalmars-d-learn
mailing list