开发者

prolog: reduce then write the value of a predicate

开发者 https://www.devze.com 2022-12-31 17:01 出处:网络
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开发者_如何学Py

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

精彩评论

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

关注公众号