Prolog中的逻辑

5 logic prolog

我怎样才能在Prolog中表达接下来的3个句子?

All summers are warm. If it not summer, then it is winter. Now it is winter.
Run Code Online (Sandbox Code Playgroud)

Cap*_*liC 5

好问题。正如@larsman(好吧,我认为现在是@FredFoo)正确地说,可以是一个大主题。他的回答确实很好。

由于您的问题可能是由自定义语言的必要性(Prolog 的主要用途之一)驱动的,因此我在这里提出了虚拟 DSL 的语法糖(这意味着现在完全是空的......)

:- op(500, fx, all).
:- op(500, fx, now).
:- op(600, xfx, are).
:- op(700, fx, if).
:- op(399, fx, it).
:- op(398, fx, is).
:- op(397, fx, not).
:- op(701, xfx, then).

all summers are warm.
if it is not summer then it is winter.
now it is winter.
Run Code Online (Sandbox Code Playgroud)

SWI-Prolog 足够友善,可以将那些被存储的操作标记为红色,即可以轻松查询。这些是声明的较高优先级单词:即 are、then、now。

?- now X.
X = it is winter.
Run Code Online (Sandbox Code Playgroud)