Method code for $list.columnize()

[Turn off line numbering]
  1: arg list, cols, @rest;
  2: var width, lines, line, separator, linelength, curcol;
  3: 
  4: // turn [...] into ".   .   ."
  5: // rest[1]==separator; rest[2]==linelength
  6: [(separator ?= "   "), (linelength ?= 78)] = rest;
  7: width = linelength / cols - separator.length();
  8: lines = [];
  9: while (list) {
 10:     line = list[1].pad(width);
 11:     list = list.subrange(2);
 12:     for curcol in [2 .. cols] {
 13:         if (list) {
 14:             line = line + separator + list[1].pad(width);
 15:             list = list.subrange(2);
 16:         }
 17:     }
 18:     lines += [line];
 19: }
 20: return lines;

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

Tlon