余由Prolog的谓词posAt(List1,P,List2),在测试位置是否在元件P的List1和List2是相等的:
posAt([X|Z], 1, [Y|W]) :-
X = Y.
posAt([Z|X], K, [W|Y]) :-
K > 1,
Kr is K - 1,
posAt(X, Kr, Y).
Run Code Online (Sandbox Code Playgroud)
测试时:
?- posAt([1,2,3], X, [a,2,b]).
Run Code Online (Sandbox Code Playgroud)
我期望输出,X = 2但我得到以下错误:
ERROR: >/2: Arguments are not sufficiently instantiated
为什么我收到此错误?