:- module(_,_).

% :- module(_,_).

% Example application of comparing non-ground terms
% (use of ==/2, \==/2, @>/2, ...)
% Inserting and item into an ordered list.

% Version with unification: 

insert_unif([], Item, [Item]).
insert_unif([H|T], Item, [H|T]) :- H = Item.
insert_unif([H|T], Item, [Item, H|T]) :- H > Item.
insert_unif([H|T], Item, [H|NewT]) :- H < Item, insert_unif(T, Item, NewT).

% Try: 
% ?- insert_unif([], a, L).
% ?- insert_unif([a,b,e], c, L).
% ?- insert_unif([a,b,e], X, L).

% Version with ==/2, @>/2, @</2

insert_ee([], Item, [Item]).
insert_ee([H|T], Item, [H|T]) :- H == Item.
insert_ee([H|T], Item, [Item, H|T]) :- H @> Item.
insert_ee([H|T], Item, [H|NewT]) :- H @< Item, insert_ee(T, Item, NewT).

% Try:
% ?- insert_ee([], a, L).
% ?- insert_ee([a,b,e], c, L).
% ?- insert_ee([a,b,e], X, L).
