Category talk:Wren-fmt: Difference between revisions

Content added Content deleted
(→‎Source code: Fixed a bug in spwrite routine.)
(Added a method to abridge long lists for printing purposes.)
Line 641: Line 641:
static v(fn, w, seq, p) { v(fn, w, seq, p, ", ", "[]", "") }
static v(fn, w, seq, p) { v(fn, w, seq, p, ", ", "[]", "") }
static v(fn, w, seq) { v(fn, w, seq, precision, ", ", "[]", "") }
static v(fn, w, seq) { v(fn, w, seq, precision, ", ", "[]", "") }

// As the 'v' method but abridges 'seq' to a maximum number
// of elements 'n' (non-overlapping) at either end or, if 'n' is negative,
// from the front only, using 'aa' as the separator. Doesn't abridge 'seq'
// unless at least one element would need to be suppressed.
static va(fn, w, seq, p, sep, bb, cc, n, aa) {
if (!(n is Num && n.isInteger && n.abs >= 1)) Fiber.abort("'n' must be a positive integer.")
if (!(aa is String)) Fiber.abort("'aa' must be a string.")
var c = seq.count
if (c <= ((n < 0) ? -n : 2*n)) return Fmt.v(fn, w, seq, p, sep, bb, cc)
var left = (seq is List) ? seq[0...n.abs] : seq.take(n.abs)
var sleft = Fmt.v(fn, w, left, p, sep, "", cc) + sep
var sright = ""
if (n > 0) {
var right = (seq is List) ? seq[-n..-1] : seq.skip(c - n)
sright = sep + Fmt.v(fn, w, right, p, sep, "", cc)
}
var res = sleft + aa + sright
if (bb != "") res = Fmt.q(res, bb)
return res
}


// Applies a 'short' formatting method to each element of a two-dimensional
// Applies a 'short' formatting method to each element of a two-dimensional