'if' in prolog?

前端 未结 10 1469
小鲜肉
小鲜肉 2020-12-03 02:12

Is there a way to do an if in prolog, e.g. if a variable is 0, then to do some actions (write text to the terminal). An else isn\'t even needed, but I can\'t find any docume

10条回答
  •  [愿得一人]
    2020-12-03 03:01

    A standard prolog predicate will do this.

       isfive(5). 
    

    will evaluate to true if you call it with 5 and fail(return false) if you run it with anything else. For not equal you use \=

    isNotEqual(A,B):- A\=B.
    

    Technically it is does not unify, but it is similar to not equal.

    Learn Prolog Now is a good website for learning prolog.

    Edit: To add another example.

    isEqual(A,A). 
    

提交回复
热议问题