I am trying to understand the following set of rules, which supposed to find the last element in a list (for instance my_list(X,[1,2,3]) gives X=3).
my_last(X,[X]).
my_last(X, [_|L]) :- my_last(X, L).
I understand the first fact - X is the last element of a list if X is the only element in it, but how does the second rule work? this looks a bit strange to me as a prolog noob, I'd love to know if there's an intutive way to interprate it. T