Prolog错误:demograph.grf:9:16:语法错误:文件意外结束

时间:2015-01-04 22:47:02

标签: prolog swi-prolog

我收到此错误: 错误:demograph.grf:9:16:语法错误:文件意外结束

file_to_list(FILE,LIST) :- 
   see(FILE), 
   inquire([],R), % gather terms from file
   reverse(R,LIST),
   seen.

inquire(IN,OUT):-
   read(Data), 
   (Data == end_of_file ->   % done
      OUT = IN 
        ;    % more
      inquire([Data|IN],OUT) ) .

Inputfile中 http://www.ist.tugraz.at/_attach/Publish/LP/demograph.grf

2 个答案:

答案 0 :(得分:1)

:- use_module(library(readutil)).
read_header_data(Stream, Header) :-
        open(Stream, read, In),
        read_lines(In, Char),
        read_line_to_codes(In, Header, Tail),
%       read_header_data(Header, Fd, Tail).
        close(In).

    read_lines(Stream, []) :-
  at_end_of_stream(Stream).

read_lines(Stream, [H|T]) :- 
  \+ at_end_of_stream(Stream).
  read(Stream, X),
  read_lines(Stream, T).

不完全是我想要的。输出应如下所示:

Lss =
[[0, 1, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 0, 0, 1, 1, 0],[0, 0, 0, 0, 0, 1, 0, 0, 0],[0, 1, 0, 0, 1, 0, 0, 1, 0],[0, 0, 0, 1, 0, 1, 0, 1, 1], [0, 0, 1, 0, 1, 0, 0, 0, 1],[0, 1, 0, 0, 0, 0, 0, 1, 0], [0, 1, 0, 1, 1, 0, 1, 0, 1],[0, 0, 0, 0, 1, 1, 0, 1, 0]] .

答案 1 :(得分:1)

现在我逐行了。

但不是0而是写入48和49和空间32.它是如何0,1和空格。

process(File) :-
open(File, read, In),
read_line_to_codes(In, Char1),
process_stream(Char1, In),
close(In).

process_stream(end_of_file, _) :- !.
process_stream('\n', _) :- !.
process_stream(Char, In) :-
process_print(Char, In),
%get_char(In, Char2),
read_line_to_codes(In, Char2),
process_stream(Char2, In).
process_print(Char, _) :-
print(Char),print(' nextChar'),nl.