langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
30
Task/Align-columns/TXR/align-columns.txr
Normal file
30
Task/Align-columns/TXR/align-columns.txr
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
@(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
|
||||
@(bind nc @(apply (fun max) (mapcar (fun length) item)))
|
||||
@(bind pi @(mapcar (lambda (row)
|
||||
(append row (repeat '("") (- nc (length row)))))
|
||||
item))
|
||||
@(bind cw @(vector-list
|
||||
(mapcar (lambda (column)
|
||||
(apply (fun max) (mapcar (fun length) column)))
|
||||
;; matrix transpose trick cols become rows:
|
||||
(apply (fun mapcar) (cons (fun list) pi)))))
|
||||
@(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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue