开发者

prolog: reduce then write the value of a predicate

This is some of the code I am writing

assert(bar(foo)),
assert(foo(bar-5)),

I'm not sure if it works though. I'm trying to get it to reduce foo by 5. I need a way to write the valu开发者_如何学Pythone of foo, but haven't found a way too. write('foo is' + foo) would be the logical way to me, but doesn't seem to work.


To be able to use a fact's value you have to unify it first. Unification is done passing unbound variable as an argument to a predicate, — bar(Moo) in our case:

facts
    bar(integer)
    foo(integer)

goal
    assert(bar(42)),
    bar(Moo),
    Baz = Moo - 5,
    assert(foo(Baz)),
    write(Baz).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜