我在探索Prolog中的寫謂詞,但它在某些時候表現有所不同。我確實通過了some posts,但我無法發現這個問題。在Prolog中使用寫謂詞時出錯
謂:
explore_write_predicate(InputList,Index):-
TempIndex is Index+1,
select(Element,InputList,TempList),
write(TempIndex).
查詢:
explore_write_predicate([1,2,3,4],1).
結果:
2
true
上面的代碼工作正常,但是當我增加一個參數寫謂詞(元)它給出了一個錯誤。
謂:
explore_write_predicate(InputList,Index):-
TempIndex is Index+1,
select(Element,InputList,TempList),
write(TempIndex,Element).
查詢:
explore_write_predicate([1,2,3,4],1).
錯誤:
No permission to call sandboxed `write(_1132,_1134)'
Reachable from:
explore_write_predicate(A,B)
swish_trace:swish_call(explore_write_predicate([1,2,3,4],1))
'$swish wrapper'(explore_write_predicate([1,2,3,4],1),A)
請幫我爲什麼這種不正常現象。 P.S我也看到了寫文檔,但無法從中得到很多。 任何幫助,不勝感激。
寫入只有一個arity。您需要將其稱爲'write([TempIndex,Element])'使其工作。 – Enigmativity
或'write(TempIndex = Element)' – CapelliC
無論如何:認真考慮用'writeq'代替! – false