I have been working on a small project with prolog. I have been noticing that when removing built in predicates like append(?List1, ?List2, ?List1AndList2)and subtract(+Set, +Delete, -Result) in favor for other alternatives ([Head | List2]when dealing with a list and single element, writing my own predicate for subtracting, etc.)
I was wondering about how optimised built in predicates generally are in prolog? I read that the complexity of subtract is |Delete|*|Set|, and I got quite a significant increase by using:
removeFriendsOfS(S, [Head | Tail], OutputAcc, Output) :-
relation(S, Head),
removeFriends(S, Tail, OutputAcc, Output),
!.
removeFriendsOfS(S, [Head | Tail], OutputAcc, Output) :-
not(relation(S, Head)),
removeFriends(S, Tail, [Head | OutputAcc], Output),
!.
Is it recommended to write your own predicates rather than to use the existing ones? I just recently started with prolog so I'm not so experienced yet.
[]. - Willem Van OnsemremoveFriends(_, [], Output, Output) :- !.- cjerik