summaryrefslogtreecommitdiff
path: root/stdlib.pl
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib.pl')
-rw-r--r--stdlib.pl29
1 files changed, 28 insertions, 1 deletions
diff --git a/stdlib.pl b/stdlib.pl
index 96132f0..5d2af9f 100644
--- a/stdlib.pl
+++ b/stdlib.pl
@@ -97,6 +97,24 @@ syntax_error(Error) :-
throw(error(syntax_error(Error), _)).
% Input and output
+parse_read_option(variables(Vs), options(variables, Vs)).
+parse_read_option(variable_names(VNames), option(variable_names, VNames)).
+parse_read_option(singletons(S), options(singletons, S)).
+
+parse_read_options([], []).
+parse_read_options([Op|Rest], [OpParsed|RestParsed]) :-
+ is_nonvar(Op),
+ parse_read_options(Rest, RestParsed),
+ ( parse_read_option(Op, OpParsed)
+ -> true
+ ; domain_error(read_option, Op)
+ ).
+
+read_term(S, Term, Options) :-
+ is_nonvar(Options),
+ is_list(Options),
+ parse_read_options(Options, ParsedOptions),
+ '$read_term'(S, Term, ParsedOptions).
read_term(Term, Options) :-
current_input(S),
@@ -106,6 +124,9 @@ read(Term) :-
current_input(S),
read_term(S, Term, []).
+read(S, Term) :-
+ read_term(S, Term, []).
+
write_term(Term, Options) :-
current_output(S),
write_term(S, Term, Options).
@@ -128,6 +149,10 @@ write_canonical(Term) :-
write_canonical(S, Term) :-
write_term(S, Term, [quoted(true), ignore_ops(true)]).
+nl :-
+ write_term('
+', []).
+
% Arithmetic comparisons defined in terms of >=. This is not the most effective way,
% but it is fine for now.
@@ -240,6 +265,8 @@ is_nonvar(T) :- nonvar(T), ! ; instantiation_error.
is_list_or_partial_list(T) :- (list(T) ; partial_list(T)), ! ; type_error(list, T).
+is_list(T) :- list(T), ! ; type_error(list, T).
+
% All solutions
findall(Template, Goal, Instances) :-
@@ -405,4 +432,4 @@ atom_concat(A1, A2, A3) :-
atom_codes(A1, Codes1),
atom_codes(A2, Codes2).
atom_concat(A1, A2, A3) :-
- instantiation_error. \ No newline at end of file
+ instantiation_error.