以下に示す短いIF/Prologのプログラムは、file_streamから読み込んだデータを行末文字(UNIXではLF)ごとにトークンに分割したリストを生成します(`iffile.pro'を参照のこと)。詳しい内容はレファレンスマニュアルのR-77ページにあるget_until/3述語の項を参照して下さい。:
listfile(Name,L) :- open(log1,file_stream(Name),[input]), readfilelist(log1,L), close(log1).
readfilelist(Stream, [X | L]) :- get_until(Stream, 0'\n', X, T), T \== 0'\z', !, readfilelist(Stream, L). readfilelist(_Stream, []).
?- listfile('test',L).
L = [hello,world]
yes
| 冒頭へ |
|