从Prolog中的文件中读取

时间:2017-07-12 22:11:43

标签: prolog

我用过'阅读'但是,当我调用时读取流 read_input('myFile.txt', N, K, B, Steps, Broken)我的口译员回答错误。 这是我的代码:

read_input('myFile.txt', N, K, B, Steps, Broken) :-
    open('myFile.txt', read, Stream),
    read_line(Stream, [N, K, B]),
    read_line(Stream, Steps),
    read_line(Stream, Broken).

    /*
     * An auxiliary predicate that reads a line and returns the list of
     * integers that the line contains.
     */  
read_line(Stream, List) :-
    read_line_to_codes(Stream, Line),
    ( Line = [] -> List = []
    ; atom_codes(A, Line),
      atomic_list_concat(As, ' ', A),
      maplist(atom_number, As, List)
    ).

0 个答案:

没有答案