1
我試圖創建一個程序,打印一個區間內有多少個平滑數字。代碼的一部分是在這裏:SWI-Prolog:錯誤:是/ 2:參數沒有充分實例化
countsmooth(_, [], _, _, Count) :-
Count is 0.
countsmooth(X, [H|T], Min, Max, Count) :-
( Y is X*H,
Y =< Max
-> ( Y >= Min
-> NewX is X*H,
countsmooth(X, T, Min, Max, NCount1),
countsmooth(NewX, [H|T], Min, Max, NCount2),
Count is (1+NCount1+NCount2)
; NewX is X*H,
countsmooth(X, T, Min, Max, NCount1),
countsmooth(NewX, [H|T], Min, Max, NCount2),
Count is (NCount1+NCount2)
)
; Count is 0
).
smooth(B, I, J, Smooths) :-
( B =< 1
-> Smooths is 0
; I =:= 1
-> primes(B, FilPrimes),
countsmooth(1, Filprimes, I, J, Count),
Smooths is (1+Count)
; primes(B, FilPrimes),
countsmooth(1, Filprimes, I, J, Count),
Smooths is Count
).
還有創建所有素數從2
到B
謂詞primes
。例如,如果B = 11
,則FilPrimes = [2,3,5,7,11]
。
當我在SWI-Prolog中撥打countsmooth
像 ?- countsmooth(1, [2,3,5,7,11,13,17,19,23], 1, 100000000, Count)
。 我得到一個結果。
但是,當我打電話smooth
像?- smooth(2,100,10000,Smooths).
我得到以下錯誤:
ERROR: is/2: Arguments are not sufficiently instantiated
通常,您可以使用SWI-Prolog的圖形跟蹤器來跟蹤執行情況。要查看在調用目標時會發生什麼,請嘗試? - gtrace,Goal。 – mat 2011-02-26 23:04:24