% https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/p01.pl
% P01 (*): Find the last element of a list
% my_last(X,L) :- X is the last element of the list L
% (element,list) (?,?)
% Note: last(?Elem, ?List) is predefined
my_last(X,[X]).
my_last(X,[_|L]) :- my_last(X,L).
% ========================= end program
How should one specify that the behavior is undetermined for an empty
input list?
What happens is that the predicate, as written,
fails when the second argument is an empty list.
Whether you wish to modify the predicate to get
a different behavior depends on your intention.
regards, chip