On Saturday, 12 December 2015 at 10:20:01 UTC, Shriramana Sharma wrote:
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...

It could be useful combined with mixins to preprocess the code you write before compiling it.

Reply via email to