RosettaCodeData/Task/Align-columns/TXR/align-columns.txr

28 lines
842 B
Text
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
@(collect)
@ (coll)@{item /[^$]+/}@(end)
@(end)
@; nc = number of columns
@; pi = padded items (data with row lengths equalized with empty strings)
@; cw = vector of max column widths
@; ce = center padding
2014-04-02 16:56:35 +00:00
@(bind nc @[apply max [mapcar length item]])
@(bind pi @(mapcar (op append @1 (repeat '("") (- nc (length @1)))) item))
2013-04-10 22:43:41 -07:00
@(bind cw @(vector-list
2014-04-02 16:56:35 +00:00
(mapcar (op apply max [mapcar length @1])
2013-04-10 22:43:41 -07:00
;; matrix transpose trick cols become rows:
2014-04-02 16:56:35 +00:00
[apply mapcar [cons list pi]])))
2013-04-10 22:43:41 -07:00
@(bind ns "")
@(output)
@ (repeat)
@ (rep :counter i)@{pi @[cw i]} @(end)
@ (end)
@ (repeat)
@ (rep :counter i)@{pi @(- [cw i])} @(end)
@ (end)
@ (repeat)
@ (rep :counter i)@\
@{ns @(trunc (- [cw i] (length pi)) 2)}@\
@{pi @(- [cw i] (trunc (- [cw i] (length pi)) 2))} @(end)
@ (end)
@(end)