Print debugging statement: Difference between revisions

m (→‎{{header|Raku}}: Fix comment: Perl 6 --> Raku)
Line 48:
result: 10
</pre>
 
=={{header|D}}==
Using templates and default arguments provides options for specifying a debug function.
The file and line could be included as either template arguments or function arguments.
<lang d>import std.stdio;
 
void debugln(string file = __FILE__, size_t line = __LINE__, S...)(S args) {
write('[', file, '@', line, "] ", args, '\n');
}
 
void debugWrite(S...)(S args, string file = __FILE__, size_t line = __LINE__) {
write('[', file, '@', line, "] ", args, '\n');
}
 
void main() {
debugln();
debugln("Hello world!");
debugln("Hello", ' ', "world", '!');
 
debugWrite();
debugWrite("Goodbye world!");
debugWrite("Goodbye", ' ', "world", '!');
}
</lang>
{{out}}
<pre>[debug.d@12]
[debug.d@13] Hello world!
[debug.d@14] Hello world!
[debug.d@16]
[debug.d@17] Goodbye world!
[debug.d@18] Goodbye world!</pre>
 
=={{header|Go}}==
1,452

edits