0
我無法理解蓄電池和孔之間的差異。Prolog平放蓄電池vs孔
形式上:
Accumulators
*Use 2 arguments to organize the building of some
output structure
*One is for result so far
*One is for final result
Holes
*Use 2 arguments to organize the building of some
output structure
*One is for final result
*One for a hole in the final result where further information can be put
這是拼合使用空穴或蓄電池? 如何將其轉換爲使用另一個?
my_flatten(In,[],Out).
my_flatten([],Acc,Acc).
my_flatten([H|T],Acc,Out) :-
my_flatten(T,Acc,TOut),
my_flatten(H,TOut,Out).
my_flatten(X,Acc,[X|Acc]) :-
X \= [],
X \= [_|_].
可能值得明確指出的是,編寫flatpair的一種常見方法是放棄中綴表示法並使用單獨的參數來填補漏洞,例如*,flatpair([],二)。 flatpair([H | T],L1,L3): - flatpair(H,L1,L2),flatpair(T,L2,L3)。 flatpair(X,[X | Z],Z)。'不需要注意中綴符號來實現孔。 :) – lurker 2014-10-07 12:42:29
'flatpair([],L - [])。'有兩個解決方案:'L = []; L = [[]]。' – false 2014-10-07 15:07:27