类似于 C/C++ 的 prolog 中的 if else if else 子句 [英] if else if else clause in prolog similar to C/C++

查看:59
本文介绍了类似于 C/C++ 的 prolog 中的 if else if else 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 c 语言中,我有类似的东西:

In c language i have something like :

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

这在 Prolog 中怎么可能?

how is this possible in Prolog?

推荐答案

(   If1 -> Then1
;   If2 -> Then2
;   ...
;   otherwise
).

注意 if-then-else 仅在您无法通过不同子句中的模式匹配来表达不同条件时才需要.可以通过模式匹配表达的所有内容都应该通过模式匹配表达,因为这通常会导致更通用、更高效的代码.

Note that if-then-else is only necessary if you cannot express the different conditions by pattern matching in different clauses. Everything that can be expressed by pattern matching should be expressed by pattern matching, as this typically leads to more general and also more efficient code.

这篇关于类似于 C/C++ 的 prolog 中的 if else if else 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆