Better prefix for $echo
Currently using $echo adds ] as a prefix, which is a bit confusing.
It might be better to use something like $ or c3c > .
File name and line also could be useful, maybe.
File-name can already be done with $$FILE (https://c3-lang.org/misc-advanced/builtins/#compiler-builtin-functions).
Same for $$LINE and $$LINE_RAW (same url).
An example:
module main;
import std::io;
fn int main() {
$echo "Compiler says hello in file " +++ $$FILE +++ " on line ";
$echo $$LINE;
io::printn("Hello, World!");
return 0;
}
Produces:
$ c3c compile test.c3
] Compiler says hello in file test.c3 on line
] 8
Program linked to executable 'main'.
So I would not include filename and line into $echo, as it is already possible to do so now. The user could very well write their own macro to include that info without having to explicitly type it:
module main;
import std::io;
macro to_string($num) {
char[] $res;
$for (;$num != 0; $num = $num / 10)
$res = { (char) ('0' + $num % 10) } +++ $res;
$endfor
return (String) $res;
}
macro compiler_message($msg) {
$echo $msg +++ " in file " +++ $$FILE +++ " on line " +++ to_string($$LINE);
}
fn int main() {
$echo "Compiler says hello in file " +++ $$FILE +++ " on line ";
$echo $$LINE;
io::printn("Hello, World!");
compiler_message("Hello from compiler");
return 0;
}
Correctly prints:
c3c compile test.c3
] Compiler says hello in file test.c3 on line
] 25
] Hello from compiler in file test.c3 on line 27
Program linked to executable 'main'.
Though I must admit that this to_string macro is a bit excessive, but I haven't found a shorter yet.
ok, makes sense. I like macros in C3, one can solve any problem with them :)
re to_string($$LINE), does $stringify($$LINE) work?
re
to_string($$LINE), does$stringify($$LINE)work?
Nope, that just prints ] $$LINE
No, that does not work. That's why I opened #1874, Christoffer told me in Discord that it would be a good addition. So in the future there will be more compile-time macros available by the compiler.
So have you decided yet? 😄
I would suggest $echo: as prefix, but I don't know what others think about it.
No consensus yet?
Ping
Maybe a poll on Discord would be the way to close this issue?
I agree with $echo, pretty clear where it comes from.
Any consensus yet?
This now has a --echo-prefix for setting it.