if else if else clause in prolog similar to C/C++

前端 未结 5 821
说谎
说谎 2021-01-18 14:53

In c language i have something like :

if(cond1)
{}
else if(cond2)
{}
else
{}

how is this possible in Prolog?

5条回答
  •  醉酒成梦
    2021-01-18 15:10

    It's not really easy to find, partly because (as noted by @mat) in Prolog there is an idiomatic alternative. You can find here SWI-Prolog documentation, albeit too much succintly, it's accurate. I cite a relevant point:

    Please note that (If -> Then) acts as (If -> Then ; fail), making the construct fail if the condition fails. This unusual semantics is part of the ISO and all de-facto Prolog standards.

提交回复
热议问题