如何根据 PROLOG 中的站点和线路事实检查站点是否存在

How to check if a station exists out of facts of stations and lines in PROLOG

我写了以下事实来表示管图

station(AL,[Metropolitan]).
station(BG,[Central]).
station(BR,[Victoria]).
station(BS,[Metropolitan]).
station(CL,[Central]).
station(EC,[Bakerloo]).
station(EM,[Bakerloo,Northern]).
station(EU,[Northern]).
station(FP,[Victoria]).
station(FR,[Metropolitan]).
station(KE,[Northern]).
station(KX,[Metropolitan,Victoria]).
station(LG,[Central]).
station(LS,[Central,Metropolitan]).
station(NH,[Central]).
station(OC,[Bakerloo,Central,Victoria]).
station(PA,[Bakerloo]).
station(TC,[Central,Northern]).
station(VI,[Victoria]).
station(WA,[Bakerloo]).
station(WS,[Northern,Victoria]).

我需要写一个谓词形式

station_exists(Station)

检查一个站是否存在,但我不知道如何写规则。我试过类似的东西:

station_exists(Station):- station(Station,_)

但它 returns 对任何站名都是正确的。有人可以帮忙吗?

您的常量以大写字母开头,因此 Prolog 认为这些是变量而不是常量。

您应该重写这些以大写或带引号的原子开头:

station(<b>al</b>, [metropolitan]).
station(<b>bg</b>, [central]).
station(<b>br</b>, [victoria]).
station(<b>bs</b>, [metropolitan]).
station(<b>cl</b>, [central]).
station(<b>ec</b>, [bakerloo]).
station(<b>em</b>, [bakerloo,northern]).
station(<b>eu</b>, [northern]).
station(<b>fp</b>, [victoria]).
station(<b>fr</b>, [metropolitan]).
station(<b>ke</b>, [northern]).
station(<b>kx</b>, [metropolitan,victoria]).
station(<b>lg</b>, [central]).
station(<b>ls</b>, [central,metropolitan]).
station(<b>nh</b>, [central]).
station(<b>oc</b>, [bakerloo,central,victoria]).
station(<b>pa</b>, [bakerloo]).
station(<b>tc</b>, [central,northern]).
station(<b>vi</b>, [victoria]).
station(<b>wa</b>, [bakerloo]).
station(<b>ws</b>, [northern,victoria]).