summaryrefslogtreecommitdiff
path: root/stdlib.pl
diff options
context:
space:
mode:
authorPeter Mikkelsen <peter@pmikkelsen.com>2021-07-20 18:05:21 +0000
committerPeter Mikkelsen <peter@pmikkelsen.com>2021-07-20 18:05:21 +0000
commite6ce8b1d6da2434232b86c7c115d7ed4961e7f5c (patch)
tree28cf7e72f1b9892cc2649437c1aad7d837109fb7 /stdlib.pl
parent1c840d5c5ab6326492542886297d5bafa2877c4d (diff)
Add op/3 and current_op/3
Diffstat (limited to 'stdlib.pl')
-rw-r--r--stdlib.pl51
1 files changed, 50 insertions, 1 deletions
diff --git a/stdlib.pl b/stdlib.pl
index c6b395f..bbefa41 100644
--- a/stdlib.pl
+++ b/stdlib.pl
@@ -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