Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add printAll() cos I always seem to need it
- Loading branch information
Showing
1 changed file
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,33 @@ | |||
"Print a line to the standard output of the virtual | "Print a line to the standard output of the virtual machine | ||
machine process, printing the given value\'s `string`, | process, printing the given value\'s `string`, or `<null>` | ||
or `\{#ab}null\{#bb}` if the value is `null`. | if the value is `null`. | ||
This method is a shortcut for: | This method is a shortcut for: | ||
process.writeLine(line?.string else \"\{#ab}null\{#bb}\") | process.writeLine(line?.string else \"<null>\") | ||
and is intended mainly for debugging purposes." | and is intended mainly for debugging purposes." | ||
// FIXME: see https://github.com/ceylon/ceylon-spec/issues/694 | // FIXME: see https://github.com/ceylon/ceylon-spec/issues/694 | ||
//see (`process.writeLine`) | //see (`process.writeLine`) | ||
by ("Gavin") | by ("Gavin") | ||
shared void print(Anything line) { | shared void print(Anything val) => | ||
process.writeLine(line?.string else "\{#ab}null\{#bb}"); | process.writeLine(stringify(val)); | ||
|
|||
"Print multiple values to the standard output of the virtual | |||
machine process as a single line of text, separated by a | |||
given character sequence." | |||
by ("Gavin") | |||
shared void printAll({Anything*} values, | |||
"A character sequence to use to separate the values" | |||
String separator=", ") { | |||
if (exists first = values.first) { | |||
process.write(stringify(first)); | |||
for (val in values.rest) { | |||
process.write(separator); | |||
process.write(stringify(val)); | |||
} | |||
} | |||
process.write(process.newline); | |||
} | } | ||
|
|||
String stringify(Anything val) => val?.string else "<null>"; |