I am working on some Prolog tutorials (nothing better to do, and I learned earlier this week, I really like programming, so I work on some paradigms) and got to the exercise asking me to write the delete_from_list / 3 predicate, which removes all the data in the list from list.
I solved it as follows:
delete_from_list([], _, []).
delete_from_list([Ah|At], X, [Ah|Bt]) :- Ah \= X, !, delete_from_list(At, X, Bt).
delete_from_list([_|Ct], X, Bt) :- delete_from_list(Ct, X, Bt).
What interests me is, and it may be more aesthetically pleasing than a practical purpose. How do you guys feel different? And why? This is mainly for a broader understanding of how to solve problems in the prolog :) For example, can this be done in rule 1?
source
share