Good I am working in a drug recommender in which I have a list of medicines and another with allergies, a fact contains (medicine, component) where X medicine contains Y component and another that is has_allergy (patient, component_allergic) where X is allergic to Y component. What I want is to get the list of medicines that do not contain that medicine but I can not get it. Example:
Tiene_alergia(Pepe, amoxicilina).
Tiene_alergia(pepe, ampicilina).
Contiene(clamoxil, amoxicilina).
Contiene(britapen, ampicilina).
Now by findall
I get 2 lists A = list of patient allergies and L = list of drug components.
I call the rule to delete (A, L, L2). L2 will be the list after filtering.
Eliminar([],[]).
Eliminar(X, [Y|Ys], L2) :- posicion(X, [Y|Ys],Pos), borrar(Pos, [Y|Ys], L2).
Eliminar([X|Xs], [Y|Ys], L2):- eliminar(X, [Y|Ys]) ; eliminar(Xs, Ys).
Posicion(E, [E, _], 0).
Posicion(E,[_|C], P):- posición (E,C,P1), P is P1+1.
Borrar(I, L, L2) :- insertar(_,I,L2,L).
Insertar(X, 0, L2, [X|L2]).
Insertar(X, Pos, [C|R], [C|R2]) :- Pos1 is Pos -1, insertar(X, pos1, R, R2).
The thing is that if I call
eliminar([amoxicilina,ampicilina],[amoxicilina, ampicilina], L2).
L2 = [ampicilina];
and this is wrong it should be []
Would there be a way to fix it?
Thanks in advance.