2012-05-03 18 views

回答

1

是否刪除列表中第一次出現的元素?您可以使用selectchk/3

+0

我怎麼刪除的項,然後添加其餘的雖然林不知道我有這樣的代碼 myappend([],[])。 (頭部|休息],[det(頭部)|輸出]): - 名詞(頭部),\t myappend(休息,輸出)。 – DorkMonstuh

+0

selectchk/3就是這樣。如果你想自己做,你必須區分這兩種情況:要麼它是你想刪除的項目,要麼不是。然後,取決於它是否是,「結果」列表將看起來不同,並且這必須反映在您的代碼中。例如,您可以使用if-then-else(If - > Then; Else)來區分這些情況。它可能看起來像:(skip(Head) - > Result = Rest; Result = [Head | Remaining],my_append(Rest,Remaining)) – mat

+0

謝謝你,我設法做到了。 :) – DorkMonstuh

0

 
'skip a specific word if its part of a list and then append the rest. Usually this item is at the start of the list and sometimes it isn't so'(_item,_list,_rest) :- 
    append(L1,[_item|L2],_list),append(L1,L2,_rest),!.