序言中的“如果"? [英] 'if' in prolog?

查看:40
本文介绍了序言中的“如果"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在序言中做一个 if,例如如果变量为 0,则执行一些操作(将文本写入终端).甚至不需要 else,但我找不到有关 if 的任何文档.

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 documentation of if.

推荐答案

一个标准的 prolog 谓词可以做到这一点.

A standard prolog predicate will do this.

   isfive(5). 

如果你用 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 是一个学习 prolog 的好网站.

添加另一个示例.

isEqual(A,A). 

这篇关于序言中的“如果"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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