aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Tsay <jasontsay@google.com>2011-06-09 17:06:47 -0700
committerJason Tsay <jasontsay@google.com>2011-06-09 18:11:53 -0700
commitf3394c8135237d150d75b197e66013092ca5a4eb (patch)
tree4bf9189d6690fd27adce9a1b9e4662f08eba2af0
parentace1c5de9f32ac57c7d385e8ca07c11c752eb67b (diff)
downloadprolog-cafe-f3394c8135237d150d75b197e66013092ca5a4eb.tar.gz
Adds consult_stream to builtins.pl
The predicate supports reading from any Java InputStream that has been suitably wrapped by a BufferedReader and a PushbackReader. Change-Id: Ieaebac64b26a76f847579316f65d5bd5e58ebd0e
-rw-r--r--src/builtin/builtins.pl14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/builtin/builtins.pl b/src/builtin/builtins.pl
index b2e1eaf..c71f3f3 100644
--- a/src/builtin/builtins.pl
+++ b/src/builtin/builtins.pl
@@ -871,7 +871,7 @@ stream_property(Stream, Stream_property) :-
!,
'$stream_property'(Stream, Stream_property).
stream_property(Stream, Stream_property) :-
- illarg(domain(term,stream_proeprty), stream_property(Stream, Stream_property), 2).
+ illarg(domain(term,stream_property), stream_property(Stream, Stream_property), 2).
'$stream_property'(Stream, Stream_property) :-
var(Stream),
@@ -1968,6 +1968,7 @@ synchronized(Object, Goal) :-
:- public cafeteria/0.
:- public consult/1.
+:- public consult_stream/1.
:- public trace/0, notrace/0.
:- public debug/0, nodebug/0.
:- public leash/1.
@@ -2064,15 +2065,18 @@ consult(File) :- atom(File), !, '$consult'(File).
stream_property(In, file_name(File)),
print_message(info, [consulting,File,'...']),
statistics(runtime, _),
+ consult_stream(File, In),
+ statistics(runtime, [_,T]).
+ print_message(info, [File,'consulted,',T,msec]),
+ close(In).
+
+consult_stream(File, In) :-
'$consult_init'(File),
repeat,
read(In, Cl),
'$consult_clause'(Cl),
Cl == end_of_file,
- !,
- statistics(runtime, [_,T]),
- print_message(info, [File,'consulted,',T,msec]),
- close(In).
+ !.
'$prolog_file_name'(File, File) :- sub_atom(File, _, _, After, '.'), After > 0, !.
'$prolog_file_name'(File0, File) :- atom_concat(File0, '.pl', File).