1

I know of the subtract predicate which removes which removes a list of items from a list

subtract([a,b,c,a,b], [a,c], X).

but is there anything like

remove([a,b,c,a,b], a, X).

I know I can modify the above in

subtract([a,b,c,a,b], [a], X).

To achieve the desired result.

But I want to know if there is another way?

EDIT:

@user27815

you did provide a very detailed answer but i'm still very much new to prolog. And perhaps I didn't ask the question correctly(My bad). If there is another way to achieve this.Is it Pre-defined or do I have to define it myself. And can I have an example?

jakHunter
  • 305
  • 3
  • 13
  • This sounds like a homework question, especially with the note you added. We typically ask you to show what you tried before we help you with your homework. But yes, you should probaby define it yourself. – Isabelle Newbie May 31 '18 at 20:15
  • I've done my homework.This i'm just adding some extra functionality to that homework just to challenge myself.Nothing more – jakHunter May 31 '18 at 20:18
  • 2
    Look up `select/3` and `delete/3`. – lurker May 31 '18 at 20:19

1 Answers1

3

Of course, there are many ways. A good way to do this is to use library reif.

See the answer to this question by repeat:

Delete vowels in a list

There are some general use predicates which are defined that you can adapt to your program.

remove(List,Element,NewList):-
     tinclude(not(list_memberd_truth([Element])),List,NewList). 
user27815
  • 4,767
  • 14
  • 28
  • Could you update this answer with some example interactions, e.g. for the queries `remove([a,b,c,a,b], a, WithoutA).`, `remove([a,b,c,a,b], Element, [b,c,b]).`, and `remove([a,b,c,a,b], Element, WithoutElement).`? – Isabelle Newbie May 31 '18 at 19:58