Skip to content
This repository
Browse code

Add printAll() cos I always seem to need it

  • Loading branch information...
commit 8f3d09c5cd48a7592915a2d2440a409960cc87dc 1 parent b9342b8
Gavin King gavinking authored

Showing 1 changed file with 24 additions and 6 deletions. Show diff stats Hide diff stats

  1. +24 6 src/ceylon/language/print.ceylon
30 src/ceylon/language/print.ceylon
... ... @@ -1,15 +1,33 @@
1   -"Print a line to the standard output of the virtual
2   - machine process, printing the given value\'s `string`,
3   - or `\{#ab}null\{#bb}` if the value is `null`.
  1 +"Print a line to the standard output of the virtual machine
  2 + process, printing the given value\'s `string`, or `<null>`
  3 + if the value is `null`.
4 4
5 5 This method is a shortcut for:
6 6
7   - process.writeLine(line?.string else \"\{#ab}null\{#bb}\")
  7 + process.writeLine(line?.string else \"<null>\")
8 8
9 9 and is intended mainly for debugging purposes."
10 10 // FIXME: see https://github.com/ceylon/ceylon-spec/issues/694
11 11 //see (`process.writeLine`)
12 12 by ("Gavin")
13   -shared void print(Anything line) {
14   - process.writeLine(line?.string else "\{#ab}null\{#bb}");
  13 +shared void print(Anything val) =>
  14 + process.writeLine(stringify(val));
  15 +
  16 +"Print multiple values to the standard output of the virtual
  17 + machine process as a single line of text, separated by a
  18 + given character sequence."
  19 +by ("Gavin")
  20 +shared void printAll({Anything*} values,
  21 + "A character sequence to use to separate the values"
  22 + String separator=", ") {
  23 + if (exists first = values.first) {
  24 + process.write(stringify(first));
  25 + for (val in values.rest) {
  26 + process.write(separator);
  27 + process.write(stringify(val));
  28 + }
  29 + }
  30 + process.write(process.newline);
15 31 }
  32 +
  33 +String stringify(Anything val) => val?.string else "<null>";

0 comments on commit 8f3d09c

Please sign in to comment.
Something went wrong with that request. Please try again.