'if' in prolog?

前端 未结 10 1503
小鲜肉
小鲜肉 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:07

    You should read Learn Prolog Now! Chapter 10.2 Using Cut. This provides an example:

    max(X,Y,Z) :- X =< Y,!, Y = Z.

    to be said,

    Z is equal to Y IF ! is true (which it always is) AND X is <= Y.

提交回复
热议问题