diff options
| author | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-15 22:04:03 +0000 |
|---|---|---|
| committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2021-07-15 22:04:03 +0000 |
| commit | 2a77288e28f2725b5621c239d2393d49f61993e8 (patch) | |
| tree | 9aeebb7b09ce2350c71dacb5d3191c494d1a3780 /stdlib.pl | |
| parent | d4fc86d5988dacfca455cac55aae71ad4fd3bb95 (diff) | |
Make read_term understand the three read options:
variables(Vars),
variable_names(VarNames),
singletons(Singles)
as required per the ISO standard
Diffstat (limited to 'stdlib.pl')
| -rw-r--r-- | stdlib.pl | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -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. |