如何在序言中实现if-then-else [英] how to implement if-then-else in prolog
本文介绍了如何在序言中实现if-then-else的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了很多东西,但我找不到如何在序言中实现以下愿望.
I have tried so many things but I could not found How I can implement following wish in prolog .
if list is empty
call foo function
else
do nothing
我做了什么:
list = [] -> foo(...)
;
fail.
但是,它不起作用
推荐答案
fail
不是什么都不做",而是失败(和回溯)".
fail
does not mean "do nothing", but "fail (and backtrack)".
您需要使用 true
代替:
( List == [] -> foo(...) ; true ),
另外,List
应该是一个变量,所以使用大写.
Also, List
should be a variable, so use upper case.
这篇关于如何在序言中实现if-then-else的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文