Prolog ERROR: demograph.grf:9:16: Syntax error: Unexpected end of file
Prolog ERROR: demograph.grf:9:16: Syntax error: Unexpected end of file
我收到这个错误:
错误: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) ) .
输入文件
http://www.ist.tugraz.at/_attach/Publish/LP/demograph.grf
:- 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]] .
现在我一行一行地得到它。
但它不是 0,而是 48,一个是 49,space 是 32。0,1 和 space.
是怎么做到的?
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.
我收到这个错误: 错误: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) ) .
输入文件 http://www.ist.tugraz.at/_attach/Publish/LP/demograph.grf
:- 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]] .
现在我一行一行地得到它。
但它不是 0,而是 48,一个是 49,space 是 32。0,1 和 space.
是怎么做到的?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.