这是我的代码,它不起作用。
skip([], []).
skip([H|T], [H|R]):-
atomic(H),
!,
skip(T, R).
skip([_|T], R):-
skip(T, R).
tails([], []).
tails([H|T], R]):-
atomic(H),
!,
skip(T, T1),
tails(T1, R).
tails([H|T], [H|R]):-
tails(H, R1),
skip(T, T1),
tails(T1, R2),
append(R1, R2, R).
如果我们输入 listL = [1, [2, 3, [4, 5] ] ]
结果应该是R = [1, 3, 5].