diff options
Diffstat (limited to 'stdlib.pl')
-rw-r--r-- | stdlib.pl | 51 |
1 files changed, 50 insertions, 1 deletions
@@ -354,6 +354,8 @@ is_list_or_partial_list(T) :- (list(T) ; partial_list(T)), ! ; type_error(list, is_list(T) :- list(T), ! ; type_error(list, T). +is_integer(T) :- integer(T), ! ; type_error(integer, T). + % All solutions findall(Template, Goal, Instances) :- @@ -628,4 +630,51 @@ appropriate_flag_values(debug, [on, off]). appropriate_flag_values(max_arity, [Val]) :- current_prolog_flag(max_arity). appropriate_flag_values(unknown, [error, fail, warning]). -appropriate_flag_values(double_quotes, [chars, codes, atom]).
\ No newline at end of file +appropriate_flag_values(double_quotes, [chars, codes, atom]). + +% Operator table modification and inspection + +op(Priority, Op_specifier, Operator) :- + is_nonvar(Priority), + is_integer(Priority), + is_nonvar(Op_specifier), + is_atom(Op_specifier), + ( operator_priority(Priority), ! + ; domain_error(operator_priority, Priority) + ), + ( operator_specifier(Op_specifier), ! + ; domain_error(operator_specifier, Op_specifier) + ), + is_nonvar(Operator), + ( atom(Operator) + -> Ops = [Operator] + ; Ops = Operator + ), + is_list(Ops), + op_helper(Priority, Op_specifier, Ops). + +op_helper(Priority, Op_specifier, []). +op_helper(Priority, Op_specifier, [Op|Ops]) :- + is_nonvar(Op), + is_atom(Op), + '$op'(Priority, Op_specifier, Op), + op_helper(Priority, Op_specifier, Ops). + +operator_priority(P) :- + integer(P), + P >= 0, + P =< 1200. + +operator_specifier(S) :- + member(S, [xf, yf, xfx, xfy, yfx, fx, fy]). + +current_op(Priority, Op_specifier, Operator) :- + ( (var(Priority) ; operator_priority(Priority)), ! + ; domain_error(operator_priority, Priority) + ), + ( (var(Op_specifier) ; operator_specifier(Op_specifier)), ! + ; domain_error(operator_specifier, Op_specifier) + ), + is_atom_or_var(Operator), + current_ops(Operators), + member(op(Priority, Op_specifier, Operator), Operators).
\ No newline at end of file |