Skip to content

Comment on Rethinking Prologparent

Comments

it is just

  [hello].
  %or
  ['hello.pl'].
  %or
  ["hello.pl"].
the '.' has syntactic meaning outside of quotes.

now to demonstrate file i/o:

we make a file hello.pl that has

  :- 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.
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.