Align columns: Difference between revisions
Content deleted Content added
No edit summary |
J: aesthetic changes |
||
Line 867: | Line 867: | ||
=={{header|J}}== |
=={{header|J}}== |
||
'''Solution''' |
'''Solution''' |
||
<lang j>'LEFT CENTER RIGHT'=: i.3 |
<lang j>'LEFT CENTER RIGHT'=: i.3 NB. justification constants |
||
NB.* alignCols v Format delimited text in justified columns |
NB.* alignCols v Format delimited text in justified columns |
||
NB. y: text to format |
|||
⚫ | |||
NB. rows marked by last character in text |
|||
NB. y is: literal list to format, fields delimited by $ |
|||
NB. columns marked by $ |
|||
NB. x |
NB. optional x: justification. Default is LEFT |
||
⚫ | |||
alignCols=: verb define |
alignCols=: verb define |
||
LEFT alignCols y |
LEFT alignCols y NB. default |
||
: |
: |
||
global=. dyad def'9!:x y'each |
|||
currboxchars=. 9!:6 '' NB. store current settings so can restore later |
|||
oldbox=. 6 16 global '';'' NB. save settings |
|||
currboxalign=. 9!:16 '' |
|||
7 17 global (11#' ');,~x NB. apply new settings |
|||
⚫ | |||
7 17 global oldbox NB. restore settings |
|||
⚫ | |||
result |
|||
9!:17 currboxalign NB. restore settings |
|||
9!:7 currboxchars |
|||
res NB. return result |
|||
)</lang> |
)</lang> |
||