What is the utility of .stringof with expressions?
Shriramana Sharma via Digitalmars-d
digitalmars-d at puremagic.com
Sat Dec 12 02:20:01 PST 2015
D currently supports:
writeln((1 + 2).stringof);
to print:
1 + 2
What is the real-world use case of this "feature"? I mean, everyone knows
what the code they write looks like, so why would they want to have a
language feature to get a string representation of it that they can print
out to the user? I mean, if at all someone wants to print out 1 + 2, they
can always say "1 + 2" and be done with it, instead of going to the
convolution of .stringof...
One thing I observe however is that:
writeln((1+ 2).stringof);
writeln((1 +2).stringof);
writeln((1 + 2).stringof);
all print "1 + 2" (without the quotes) so it's not a simple compiler dumps
to string thing, but still I don't understand what this can be useful for...
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d
mailing list