Anonymous user
Align columns: Difference between revisions
→{{header|Prolog}}
(→{{header|Prolog}}: Marked incorrect due to the presence of the extra quotes in the output.) |
|||
Line 1,468:
=={{header|Prolog}}==
▲Works with SWI-Prolog.<BR>
<lang Prolog>aligner :-
L ="Given$a$text$file$of$many$lines,$where$fields$within$a$line$
Line 1,484 ⟶ 1,482:
% each line is a list of words
parse(L, 0, N, LP, []),
% we need to add
N1 is N+
% words will be left aligned
sformat(AL, '
% words will be centered
sformat(AC, '
% words will be right aligned
sformat(AR, '
write('Left justified :'), nl,
maplist(affiche(AL), LP), nl,
write('Centered justified :'), nl,
maplist(affiche(AC), LP), nl,
write('Right justified :'), nl,
maplist(affiche(AR), LP), nl.
affiche(F, L) :-
maplist(
nl.
nl.
string_to_atom(W,AW),
sformat(AF, F, [AW]),
write(AF).
Line 1,548 ⟶ 1,552:
Output :
<lang Prolog> ?- aligner.
Left justified :
'Given' a text file of many 'lines,' where fields within a line ▼
Centered justified :
justified, right justified, or center justified within its column.
Right justified :
justified, right justified, or center justified within its column.
true .
▲ 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.'
</lang>
|