I need to read the contents of a fixed-format text file into a list of lists (LL) in Prolog but I want to exclude the first and last element on each line from the list for that line. The very first line of the input file includes the number of rows (number of lists in LL) and columns (number of elements per list in LL). An example input file with 3 rows and 4 columns is
3 4
A B C D Cd
1 9 3 7 4 7
2 6 8 4 0 32
3 2 4 3 8 42
Ab 140 21 331 41 55
and I would like
LL = [[9,3,7,4],[6,8,4,0],[2,4,3,8]]
How can I exclude the first and last element on each line from LL?
I have tried reading the SWI-Prolog documentation and searching for relevant threads here, but I have been unsuccessful.
readAll( InStream, [W|L] ) :-
readWordNumber( InStream, W ), !,
readAll( InStream, L ).
readAll( InStream, [] ) :-
\+readWordNumber(InStream,_).
lst_2_lst_of_lst([], _N, []).
lst_2_lst_of_lst(L, N, LL) :-
lst_2_lst_of_lst_helper(L, 1, N, LL).
lst_2_lst_of_lst_helper([H|T], N, N, [[H]|LL]):-
lst_2_lst_of_lst(T, N, LL).
lst_2_lst_of_lst_helper([H|T], N1 , N, [[H|TMP]|LL]):-
N2 is N1 + 1,
lst_2_lst_of_lst_helper(T, N2 , N, [TMP| LL]).
After calls to
...readAll(F,Input), ...
lst_2_lst_of_lst(Input, C, LL)
(C is 4, read in from first line of F, the text file)
My current result looks like this
LL = [[1,9 3 7 4 7,2,6 8 4 0 32],[3,2 4 3 8 42,Ab,140 21 331 41]]
and I would like it to look like this
LL = [[9,3,7,4],[6,8,4,0],[2,4,3,8]]