chapel
chapel copied to clipboard
writeln, spaces, and literals
It's common to see Chapel code like this:
writeln(a, " ", b, " ", c);
because otherwise, writeln will glom together the output:
writeln(1, 2, 3); // 123
In Python 3, the print
function automatically adds spaces between multiple elements:
$ python3
>>> print(1,2)
1 2
Could Chapel do this as well?
The immediate counter-argument is something like this - well, wouldn't printing with a different separator become awkward? Like the following:
writeln(1, "+", 2, "+", 3); // 1+2+3 or 1 + 2 + 3 ?
My first reaction would be that writeln
could recognize an ioLiteral
and in that event not add spaces between arguments:
writeln(1, new ioLiteral("+"), 2, new ioLiteral("+"), 3); // 1+2+3
Then, my second thought is that string literals could be treated automatically as ioLiterals within writeln
. That would make the first "+" case above be equivalent to the second. Additionally, it would make
readln(int1, "+", int2, "+", int3);
actually function reasonably, because the "+" will be interpreted as delimeters, rather than being a compilation error (can't read into a string literal).