I need to delete an element of a list in prolog, but it only work when you put the list in the consult for example: eliminar(1,[1,2,3], X). it returns X=2,3, but when I wanna delete an element of the list "aves" it gives me false eliminar(loro,aves,X) it returns false.
aves([aguila, paloma, loro, canario]).
% Predicado para eliminar un elemento de una lista
eliminar(X,[X|Xs], Xs).
eliminar(X,[Y|Ys] , [Y|Zs]) :- eliminar(X,Ys,Zs).
I'm trying putting [aves], and it doesn't work
Only capital words are variables (
_varsare special case) in prolog. When you writeaves, it will not be substituted to anything else.If have declared,
aves([...]).then to get that list back you have to queryaves(X)which returns the list as the variableX.So your query should be: