Talk:Align columns: Difference between revisions
Content added Content deleted
m (→J solution) |
(→J solution: poll: short or general?) |
||
Line 50: | Line 50: | ||
|} |
|} |
||
::--[[User:DanBron|DanBron]] 23:32, 2 December 2008 (UTC) |
::--[[User:DanBron|DanBron]] 23:32, 2 December 2008 (UTC) |
||
=== poll: short or general? === |
|||
Given that: |
|||
# The <code>9!:27</code> version confused even a veteran J user, and |
|||
# using these foreigns has side effects which would need to be reverted after the desired effect is acheived, further cluttering the solution, and |
|||
# using foreigns that control global formatting to acheive local formatting might be considered cute at best, and |
|||
# the task calls for ''allow[ing] each word in a column to be [aligned]'', which could imply the need to align words or columns independently, then |
|||
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. |
|||
If so, here's a candidate solution: |
|||
colAlign =: 'L'&$: : (format@:align parse) |
|||
format =: [: > (,. ' '&,.)&.>/ |
|||
align =: cols |."1&.>~ ('';1) <;.1 rotation |
|||
cols =: <@:>"1@:|:@:] |
|||
rotation =: (<.@*"1 2: %~ 'LCR'&i.)~ offset |
|||
offset =: (-"1 >./)@:(#&>) |
|||
parse =: [: (-@:(-:{:) }. <;._2@:,~)&>/ '$'; LF ; ] |
|||
Example of use: |
|||
colAlign text NB. Default is left justification. |
|||
'C' colAlign text NB. Can specify a different justification for all columns, |
|||
'RCLRCLRCLRCL' colAlign text NB. or for each column independently, |
|||
(6 12 (] {~ (?.@$ #)) 'LCR') colAlign text NB. or for each word independently. |
|||
Of course, we could retain both, and lead with the short one. But that might be overkill. |
|||
--[[User:DanBron|DanBron]] 02:39, 3 December 2008 (UTC) |
|||
== Output Question == |
== Output Question == |