我想將通過整數分隔的單詞列表分割成列表列表。序言:整數列表中的整數列表
樣品的查詢和預期的結果:
?- separatewords([h,e,l,l,o,1,o,v,e,r,3,t,h,e,r,e], X).
X = [[h,e,l,l,o],[o,v,e,r],[t,h,e,r,e]].
我已經取得了以下幾件事: 拆分列表進入第一個整數前一個列表和一個第一整數後:
樣品查詢與結果:
?- take1word([h,e,l,l,o,1,o,v,e,r,3,t,h,e,r,e], X, Y).
X = [h,e,l,l,o], Y = [o,v,e,r,3,t,h,e,r,e]. % OK
我的代碼:
take1word([H|T],[],T) :-
integer(H).
take1word([H|T],[H|Hs],Y) :-
( float(H), take1word(T,Hs,Y)
; atom(H), take1word(T,Hs,Y)
).
對於分離的話我的代碼如下:
separatewords([],[]).
separatewords([H|T],L) :- separatewords(T,[take1word([H|T],)|L]).
只給我false
結果,但我不知道,我在做什麼錯。
工作 - 謝謝! – 2014-11-22 14:54:51