I'm new to Prolog and st开发者_StackOverflow中文版uck on some programming homework. one of them should work like this:
myDel(1, [1, 2, 1, 3, 1, 4], M).
the result should be:
M = [2, 3, 4].
to solve this, one can only use append recursively and can not use the built-in delete.
Can somebody help?
I must say that it's quite difficult to help without just spoon-feeding you the answer. Prolog is a bit like that. Here's a partial answer that hopefully doesn't give too much away:
myDel(N, [], []).
myDel(N, [N|T], U) :- ...
Sorry! Cut was needed.
myDel(N,L,DelL) :-
append(L0,[N|R],L),
myDel(N,R,DelL2),
append(L0,DelL2,DelL),
!.
myDel(_,L,L).
精彩评论