praise: optional comma at the end of argument list is a life saver for generated code
Ali Çehreli
acehreli at yahoo.com
Sun Sep 13 19:28:05 UTC 2020
Yes, accepting that trailing comma is very useful in many contexts.
Related, I use std.format's %( and %) specifiers, which automatically
remove the extra delimiters at the end:
import std.stdio;
void main() {
writefln!"%(%s, %)"([1, 2, 3]);
}
Prints
1, 2, 3
When we want, we can use %| to mean "keep the delimiters up to this place":
writefln!"%(%s,%| %)"([1, 2, 3]);
Now the comma is printed as well but not the following space:
1, 2, 3,
I wish it had an additional feature where we could say "use this
delimiter before the last one" so we could inject e.g. and "and":
1, 2, and 3
As far as I know, it doesn't exist.
Ali
More information about the Digitalmars-d
mailing list