什么是-> Prolog中的运算符,该如何使用? [英] What's the -> operator in Prolog and how can I use it?

查看:68
本文介绍了什么是-> Prolog中的运算符,该如何使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一本书中已经读过它,但是根本没有解释.我也从未在程序中看到它.是Prolog语法的一部分吗?这是为了什么?您使用它吗?

I've read about it in a book but it wasn't explained at all. I also never saw it in a program. Is part of Prolog syntax? What's it for? Do you use it?

推荐答案

它表示含义.仅当左侧为true时,才执行右侧.因此,如果您有此代码,

It represents implication. The righthand side is only executed if the lefthand side is true. Thus, if you have this code,

implication(X) :-
  (X = a ->
    write('Argument a received.'), nl
  ; X = b ->
    write('Argument b received.'), nl
  ;
    write('Received unknown argument.'), nl
  ).

然后,它将根据it参数编写不同的内容:

Then it will write different things depending on it argument:

?- implication(a).
Argument a received.
true.

?- implication(b).
Argument b received.
true.

?- implication(c).
Received unknown argument.
true.

(链接至文档. )

这篇关于什么是-> Prolog中的运算符,该如何使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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