开发者

Prolog Conditional Not Evaluating

开发者 https://www.devze.com 2022-12-09 21:43 出处:网络
I\'m trying to simply do a conditional in prolog like this: ((Life==dead)->Trans=no). I thought the above code would evaluate as if Life == dead, then Trans= no, but for some reason its not? Thank开

I'm trying to simply do a conditional in prolog like this:

((Life==dead)->Trans=no).

I thought the above code would evaluate as if Life == dead, then Trans = no, but for some reason its not? Thank开发者_JAVA百科s.


Works for me:

?- ((Life==dead)->Trans=no).
false.

?- Life = dead, ((Life == dead) -> Trans=no).
Life = dead,
Trans = no.

Life == dead will only be true if Life is already bound to dead.

Also, this is a rather strange construct that it is rarely needed in practice, (x -> y ; z) is much more common.

0

精彩评论

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