:- module(_,_).

% Examples of ISO I/O

% Try:
% ?- tell(foo), write( f(g(a,[1,2,3])) ), told.
% We use a library predicate to see exact contents of foo: 
% ?- set_prolog_flag(write_strings,on).
% ?- show_file(foo).

% We define write_list_to_file/2: 

write_list_to_file(L,F) :- 
    telling(OldOutput),             % Grab current output stream.
    tell(F), write_list(L), told,   % Write into F, close.
    tell(OldOutput).                % Reset previous output stream.

write_list([]).
write_list([X|Xs]):-
    write(X),
    % write_canonical(X),
    write('.'),
    nl,
    write_list(Xs).

% Try:
% ?- write_list_to_file([ f(a), m, g(k)],foo).
% ?- show_file(foo).
% ?- see(foo), read(X), seen.
% ?- see(foo).
% ?- read(X).
% ?- read(X).
% ?- read(X).
% ?- seen.

% We use other library predicates to print the exact contents of files:
:- use_module(library(stream_utils)).
show_file(F) :- 
    file_to_string(F,L),
    format("~s",[L]).
