Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions utils.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,19 @@

/* ----------------------------------------------------------------- */

def_forall:-
current_predicate(forall/2) -> true
;
assertz((
forall(Cond, Action):-
\+ (Cond, \+ Action)
)).

def_inordset:-
current_predicate(ord_memberchk/2) -> true
;
:- if(\+ predicate_property(forall(_, _), _)).
forall(Cond, Action):-
\+ (Cond, \+ Action).
:- endif.

:- if(\+ predicate_property(ord_memberchk(_, _),_ )).
% Minimal implementation of ordsets
assertz((
ord_memberchk(E, [H|T]) :-
( E == H % Membership check succeeds if found
-> true
; E @> H % Continue searching (only if E > H)
-> ord_memberchk(E, T)
)
)).
ord_memberchk(E, [H|T]) :-
( E == H % Membership check succeeds if found
-> true
; E @> H % Continue searching (only if E > H)
-> ord_memberchk(E, T)
).

% ord_insert(+Set, +Element, -NewSet)
% Inserts Element into Set only if it is not already present, maintaining order.
Expand All @@ -51,9 +44,5 @@
; ord_insert(T, E, T1), % Keep looking
NewSet = [H|T1]
).
:- endif.

iniutil:-
def_forall,
def_inordset.

:- initialization(iniutil).