:- use_module(library(readutil)).
readmyfile(Filename) :-
open(Filename,read, Stream),
read_line_to_string(Stream,Input),
write("The line is:"), nl,
write(Input), nl,
close(Stream),
%or slurp the whole thing
read_file_to_string(Filename,WholeFile,[encoding(text)]),
%lets use the formatted output predicate
format("The file ~s has the following contents ~n~s ~n",[Filename,WholeFile]).
then launch swi and
?- [hello].
true.
?- readmyfile('hello.pl').
The line is:
:- use_module(library(readutil)).
The file hello.pl has the following contents
...
...
...
true.
Comments
it is just
the '.' has syntactic meaning outside of quotes.now to demonstrate file i/o:
we make a file hello.pl that has
then launch swi and