When you are debugging, it's very useful to do this:
var = calc()
print("var:", var)
Is there any language where this is easy to do? In C and C++ you can use the stringify macro operator # and in Ruby I found this question:
http://stackoverflow.com/questions/2603617/ruby-print-the-variable-name-and-then-its-value
The solution that uses a symbol :var and a block is what I want.
In D, I used this:
void trace(alias msg)() {
writeln(msg.stringof ~ ":" ~ to!string(msg));
}
But I'm not sure it's the best way, because it works only in simple cases. I have tried several ways, but sometimes you can get the string, but not the value (because variables are out of scope), or you have to mixin the template first and then call the function.
And what about other languages? Python? F#? Boo? Shell script (whichever shell)? Perl? (I prefer to stay away from Perl, tho). Tcl? Lisp, Scheme? Java? (it's highly unlikely that Java can do this).
Even in the languages where I found some kind of solution, it only works for simple cases. What if I want to print an arbitrary expression?
If I were designing a language, this feature would be a must-have. :-)