我正在尝试使用read_line_to_codes(Stream,Result)
and atom_codes(String,Result)
。这两个谓词首先从文件中读取行作为字符代码数组,然后将该数组转换回字符串。然后我想将所有这些字符串输入到字符串数组中。
我尝试了递归方法,但是对于如何在开始时实际将数组实例化为空以及process_the_stream/2
.
/*The code which doesn't work.. but the idea is obvious.*/
process_the_stream(Stream,end_of_file):-!.
process_the_stream(Stream,ResultArray):-
read_line_to_codes(Stream,CodeLine),
atom_codes(LineAsString,CodeLine),
append_to_end_of_list(LineAsString,ResultArray,TempList),
process_the_stream(Stream,TempList).
我希望使用递归方法将行数组作为字符串。