/* Read a file line by line in Picat. http://rosettacode.org/wiki/Read_a_file_line_by_line """ Read a file line by line Read a file one line at a time, as opposed to reading the entire file at once. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ main => go. % For reasonable sized files go => foreach(Line in read_file_lines("unixdict.txt")) println(Line) end. % For very large files go2 => FD = open("unixdict.txt"), while (not at_end_of_stream(FD)) Line = read_line(FD), println(Line) end, close(FD), nl. % Loading data (terms) % cl_facts(FactList) loads the system with the facts which can then % used as facts defined in the program. % % The file must be Picat terms, i.e. a fact and ends with "." + at least one space. % Example % % data(one,1). % data(two,2). % data(three,3). % data(four,4). % go3 => Terms = read_file_terms("read_a_file_line_by_line.txt"), println(terms=Terms), cl_facts(Terms), All=findall(X=Y,data(X,Y)), println(All), nl.