Method code for $list.columnize2()

[Turn on line numbering]
arg list, cols, @rest;
var width, lines, line, separator, linelength, x, handled_length;

// turn [...] into ".   .   ."
// rest[1]==separator; rest[2]==linelength
[(separator ?= "   "), (linelength ?= 78)] = rest;
width = linelength / cols - separator.length();
lines = [];
for x in [1 .. list.length() / cols] {
    line = list.subrange(x * cols - 1, cols).mmap('pad, width).join(separator);
    lines += [line];
}
handled_length = x * cols;
if (list.length() != handled_length)
    lines += [list.subrange(handled_length + 1).mmap('pad, width).join(separator)];
return lines;

// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit

Tlon