Is there a way to know what type is a variable in Prolog? I have the code
test:-
writeln('Please enter the absolut file name :'),
read(FileName),
write('Opening file '),
write(FileName),nl,
open(FileName,read,Stream),
read_file(Stream,Lines),
close(Stream),
parseLines(Lines).
% used on reading the text file
read_file(Stream,[]) :-
at_end_of_stream(Stream).
% used on reading the text file
read_file(Stream,[X|L]) :-
\+ at_end_of_stream(Stream),
read(Stream,X),
read_file(Stream,L).
parseLines(Lines):-
%primele 2 linii contin lista cu barbatii si list cu femeile iar
%restul liniilor contin preferintele acestora
Lines=[LB|[LF|LPrefs]],
writeln(LB),
atom_length(LB,2).
And I get the error (when running test)
ERROR: [Thread pdt_console_client_0_Default Process] atom_length/2: Type error: `list' expected, found `man([m1,m2])'
The input text file contains
man = {m1, m2}.
women = {w1, w2}.
m1: w1 > w2.
m2: w1 > w2.
w1: m1 > m2.
w2: m1 > m2.
I am trying to parse that file but anything I try I get that error, like the things in the Lines read from the file are not string,atoms , I have no idea what to do to fix this.
P.S.Any idea on how to fast/simple parse the file? It feels strange that parsing the input for the problem is much harder then solving the problem.
Thanks.
Edit: I found the compound predicate and the line read from files is a compound term. Edit2: My goal is to read the data in that file and assert it or similar, I want to solve the stable marriage problem, I solve it but I can't figure out this part of reading the input from this file format.
Edit3: I have other input files that have lines like:
alan: christine > tina > zoe > ruth > sarah.
and this lines fail when trying to read them as terms with read_file_to_terms because of the multiple > operators, so I think not all my inputs are valid Prolog