root/trunk/examples/operators/reverse.lgt

Revision 4601, 0.8 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(reverse).
3
4
5    :- info([
6        version is 1.0,
7        author is 'Paulo Moura',
8        date is 2004/2/16,
9        comment is 'Reads and writes a simple table of facts from and to files for testing operator handling code.']).
10
11    :- op(500, xfx, next).              % local object operators, not visible outside this object
12    :- op(500, xfx, previous).
13
14    :- initialization(reverse_file).
15
16
17    reverse_file :-
18        open('next.txt', read, RStream),
19        open('previous.txt', write, WStream),
20        read(RStream, Term),            % local operators are used when reading terms ...
21        process(Term, RStream, WStream).
22
23    process(end_of_file, RStream, WStream) :-
24        close(RStream),
25        close(WStream).
26
27    process(X next Y, RStream, WStream) :-
28        write(WStream, Y previous X),   % ... and when writing terms
29        write(WStream, '.'), nl(WStream),
30        read(RStream, Next),
31        process(Next, RStream, WStream).
32
33
34:- end_object.
Note: See TracBrowser for help on using the browser.