This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/operators/reverse.lgt
pmoura 9f1b358c04 Logtalk 2.26.2 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1486 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2005-12-24 18:00:21 +00:00

35 lines
859 B
Plaintext

:- object(reverse).
:- info([
version is 1.0,
author is 'Paulo Moura',
date is 2004/2/16,
comment is 'Reads and writes a simple table of facts from and to files for testing operator handling code.']).
:- op(500, xfx, next). % local object operators, not visible outside this object
:- op(500, xfx, previous).
:- initialization(reverse_file).
reverse_file :-
open('next.txt', read, RStream),
open('previous.txt', write, WStream),
read(RStream, Term), % local operators are used when reading terms ...
process(Term, RStream, WStream).
process(end_of_file, RStream, WStream) :-
close(RStream),
close(WStream).
process(X next Y, RStream, WStream) :-
write(WStream, Y previous X), % ... and when writing terms
write(WStream, '.'), nl(WStream),
read(RStream, Next),
process(Next, RStream, WStream).
:- end_object.