Why macro instead of a function?

why @sprintf instead of sprintf?

1 Like

Now, it can count as a historical accident, like @evalpoly.

From 1.6, there is Printf.Format for format string and Printf.format for producing strings or writing directly to the output.

1 Like
1 Like

Because then the parsing of the format string can be performed at compile time (with the resulting types known to the compiler), not runtime.

(You can also use Printf.format(Printf.format"...", args...) to do compile-time parsing of the format string "...", but that’s a lot more cumbersome to write than @sprintf("...", args...).)