38 lines
2.3 KiB
Text
38 lines
2.3 KiB
Text
{def txt
|
|
Given$a$text$file$of$many$lines,$where$fields$within$a$line\$are$delineated$by$a$single$'dollar'$character,$write$a$program\$that$aligns$each$column$of$fields$by$ensuring$that$words$in$each\$column$are$separated$by$at$least$one$space.\$Further,$allow$for$each$word$in$a$column$to$be$either$left\$justified,$right$justified,$or$center$justified$within$its$column.}
|
|
-> txt
|
|
{def columns // function's name
|
|
|
|
{def columns.r // loop function
|
|
{lambda {:just :a :b}
|
|
{if {A.empty? :a} // end of loop
|
|
then :b // return the string
|
|
else {columns.r :just // justification
|
|
{A.rest :a}. // loop on next char
|
|
{if {W.equal? {A.first :a} \} // if end of line
|
|
then < tr> :b // open a table row
|
|
else {if {W.equal? {A.first :a} $} // if space between words
|
|
then < td style="text-align::just;">:b // open a table data with justif
|
|
else {A.first :a}:b }} } }}} // else add character
|
|
|
|
{lambda {:just :txt} // main function
|
|
{table // open an HTML table
|
|
{columns.r // call the loop function
|
|
:just // justification
|
|
{A.reverse {A.split ${:txt}}} // split and reverse
|
|
. // end point
|
|
}}}}
|
|
-> columns
|
|
|
|
|
|
{columns left txt}
|
|
-> Given a text file of many lines, where fields within a line
|
|
are delineated by a single 'dollar' character, write a program
|
|
that aligns each column of fields by ensuring that words in each
|
|
column are separated by at least one space.
|
|
Further, allow for each word in a column to be either left
|
|
justified, right justified, or center justified within its column..
|
|
|
|
|
|
|
|
{columns center txt} and {columns right txt} outputs can be seen in this website: http://lambdaway.free.fr/lambdawalks/?view=align_columns
|