These are predicates which reads from input file
read_line(L,C) :-
get_char(C),
(isEOFEOL(C), L = [], !;
read_line(LL,_),% atom_codes(C,[Cd]),
[C|LL] = L).
%Tests if character is EOF or LF.
isEOFEOL(C) :-
C == end_of_file;
(char_code(C,Code), Code==10).
read_lines(Ls) :-
read_line(L,C),
( C == end_of_file, Ls = [] ;
read_lines(LLs), Ls = [L|LLs]
).
Input file:
A B
C D
E F
G H
read_lines(L)
returns L = [[A, ,B],[C, ,D],[E, ,F],[G, ,H]]
. My goal is to replace all the spaces and merge list of lists into single list. So expected output should look like: L = [A-B,C-D,E-F,G-H]
.
What I got so far is modified read_line
function:
read_line(L,C) :-
get_char(C),
( (char_code(C,Code), Code == 32)
-> C = '-'
; C = C),
(isEOFEOL(C), L = [], !;
read_line(LL,_),% atom_codes(C,[Cd]),
[C|LL] = L).
When I use it, Prolog says Syntax error: Unexpected end of file
. What's wrong with that?