prolog:succ(x,y)逃避参数是否足够实例化?
我的程序看起来很少:
test(1, N, M) :-
succ(N, NN),
random(1, 4, X),
test(X, NN, M).
test(2, N, M) :-
succ(MM, M),
random(1, 4, X),
test(X,N, MM).
test(3, N, M) :-
N=M.
我现在的目的是计算变量m
,以便
test(1,1,M).
在此上下文中进行调用:有意义。我知道在此示例中,我可以轻松地替换
test(2, N, M) :-
succ(MM, M),
random(1, 4, X),
test(X,N, MM).
来
test(2, N, M) :-
succ(N, NN),
random(1, 4, X),
test(X,NN, M).
解决问题。但是在我更复杂的程序中,这是不可能的。而且我没有线索将这个示例替换为另一个示例来排除这种可能性。
所以我的问题: 他们的可能性是以这种方式概括谓词succ
谓词,这是可能的。含义succ(x,y)
将给出y = x + 1
,y在n = m
后递归计算y,在中调用测试(3,N,M)
。
I have a program looking like this minimal example:
test(1, N, M) :-
succ(N, NN),
random(1, 4, X),
test(X, NN, M).
test(2, N, M) :-
succ(MM, M),
random(1, 4, X),
test(X,N, MM).
test(3, N, M) :-
N=M.
My aim now is to calculate the variable M
, such that the call:
test(1,1,M).
makes sense in this context. I know in this example I could easily replace
test(2, N, M) :-
succ(MM, M),
random(1, 4, X),
test(X,N, MM).
by
test(2, N, M) :-
succ(N, NN),
random(1, 4, X),
test(X,NN, M).
to solve the problem. But in my more complicated program this is not possible. And I don't have the clue to replace this example by another one to exclude this possibility.
So my question:
is their a possibility to generalize the predicate succ
predicate in such a way, the function test would be possible. Means succ(X,Y)
would give Y = X + 1
and Y is calculated recursively after N = M
is called in test(3, N, M)
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论