Talk:Align columns: Difference between revisions
Content added Content deleted
(→J solution: poll: short or general?) |
|||
Line 61: | Line 61: | ||
should we scrap our short (if cute) solution, and replace it with a longer, but more general solution? As a (possibly desirable) side-effect, a solution which eschewed the foreigns would be more comparable to others written in languages which lack a built-in formatting & alignment facility. |
should we scrap our short (if cute) solution, and replace it with a longer, but more general solution? As a (possibly desirable) side-effect, a solution which eschewed the foreigns would be more comparable to others written in languages which lack a built-in formatting & alignment facility. |
||
We could use the original solution: |
|||
colalign=: verb define |
|||
'L' colalign y NB. default to left-justify all columns |
|||
: |
|||
D=. '$' NB. the column delimiter |
|||
afD=. ,&.> (#&D&.> @: (D&~: @: {: &.>)) NB. assure final delimiter (verb) |
|||
T0=. afD <;._2 y NB. text arranged as lines |
|||
T1=. > <;._2&.> T0 NB. as word grid |
|||
Alignment=. x, (({:$T1)-#x) # {:x |
|||
if. 'C' e. Alignment do. |
|||
Colwidths=. >./"2 Sizes=. > #&.>"0 T1 |
|||
CPad=. ('C'=Alignment)*"1 <.2%~ Sizes -~"1 Colwidths |
|||
T2=. T1 ,~&.>"0 CPad #&.>"0 ' ' NB. as center-justify-padded grid |
|||
else. T2=. T1 end. |
|||
if. doesR=. 'R' e. Alignment do. |
|||
whereR=.'R'=Alignment |
|||
T3=. (($T2)$whereR)}(,: |.&.>) T2 NB. as right-justify-prepared grid |
|||
else. T3=. T2 end. |
|||
T4=. >@{."1&.> 1 <@|:;.1 |: T3 NB. as columns |
|||
if. doesR do. |
|||
T5=. whereR }(,: |."1&.>) T4 NB. as rt-jstfy-completed columns |
|||
else. T5=. T4 end. |
|||
SP=. <|:,:' '#~#T0 NB. space-column to interleave with text columns |
|||
>,"1&.>/ }. ,|: SP,,:T5 |
|||
) |
|||
Example use: |
|||
colalign text NB. Default is left justification |
|||
'C' colalign text NB. can be changed. |
|||
Or another candidate, such as: |
|||
colAlign =: 'L'&$: : (format@:align parse) |
colAlign =: 'L'&$: : (format@:align parse) |
||
format =: [: > (,. ' '&,.)&.>/ |
format =: [: > (,. ' '&,.)&.>/ |
||
Line 76: | Line 106: | ||
(6 12 (] {~ (?.@$ #)) 'LCR') colAlign text NB. or for each word independently. |
(6 12 (] {~ (?.@$ #)) 'LCR') colAlign text NB. or for each word independently. |
||
Of course, we could |
Of course, we could include 2 solutions; lead with the short one, finish with the general one. But that might be overkill. |
||
--[[User:DanBron|DanBron]] 02:39, 3 December 2008 (UTC) |
--[[User:DanBron|DanBron]] 02:39, 3 December 2008 (UTC) |