Hello I wish some advice or words about this task:
Define a statement with three parameters where the first one is a list, the second one is an element (atom or list) and the last one is a list which must accomplish it is equal to the first but first's list' elements which match second parameter,are gone.
Examples:
> elimina([f, e, d, [a, h], a, d, a], a, L)
L = [f, e, d, [a, h], d]
> elimina([f, e, d, [ a, h], a, [d, a]], [a, h], L)
L = [f, e, d, a, [d, a]]
I tried:
elimina([],_,[]).
elimina([X],X,[]).
elimina([X],Y,[X]).
elimina([H|T],H,Result) :-
elimina([T],H,Result).
elimina([H|T],Y,Result):-
elimina([T],H,Result).
I have the doubt about what to write when I shout the recursive call:
elimina([T],H,Result).
Because first I don't know how differently should be the behave when the input second element matchs the head rather than don't matching the head; so I put the same call.
Also I doubt because: Is really needed to put the base case: elimina([X],Y,[X]).
? I thought we could pass the exercise with just matching the element to delete with the ones which are really into the list.
Thank you for your time.