Category talk:Wren-fmt: Difference between revisions

→‎Source code: Added a generic method for tabular printing.
(→‎Source code: Added Fmt.u method for Unicode codepoint lists. Removed type aliases which are no longer needed.)
(→‎Source code: Added a generic method for tabular printing.)
Line 804:
static print(fmt, a1) { System.print(slwrite(fmt, [a1])) }
static lprint(fmt, a) { System.print(slwrite(fmt, a)) }
 
// Prints (with a following \n) a sequence 'a' to stdout in tabular form
// with a maximum of 'rowSize' elements per row. 'fmt' is applied individually
// to each element and formatted elements are separated by a single space.
static tprint(fmt, a, rowSize) {
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 (!((rowSize is Num) && rowSize.isInteger && rowSize > 0)) {
Fiber.abort("Third argument must be a positive integer.")
}
fmt = fmt + " "
var count = 0
for (e in a) {
Fmt.write(fmt, e)
count = count + 1
if (count % rowSize == 0) System.print()
}
if (count % rowSize != 0) System.print()
}
 
// Prints (with a following \n) an array 'a' to stdout using a typical layout.
9,487

edits