Category talk:Wren-fmt: Difference between revisions

Content added Content deleted
m (→‎Source code: Fixed syntax highlighting.)
(→‎Source code: Added a generic method for columnar printing.)
Line 822: Line 822:
}
}
if (count % rowSize != 0) System.print()
if (count % rowSize != 0) System.print()
}

// Prints (with a following \n) a sequence 'a' to stdout in columnar form
// with a maximum of 'colSize' elements per column. 'fmt' is applied individually
// to each element and formatted elements are separated by a single space.
static cprint(fmt, a, colSize) {
if (!(fmt is String)) Fiber.abort("First argument must be a string.")
if (!(a is Sequence)) Fiber.abort("Second argument must be a sequence.")
if (!((colSize is Num) && colSize.isInteger && colSize > 0)) {
Fiber.abort("Third argument must be a positive integer.")
}
fmt = fmt + " "
for (i in 0...colSize) {
var j = i
while (j < a.count) {
Fmt.write(fmt, a[j])
j = j + colSize
}
System.print()
}
}
}