2017-07-14 88 views
4

說我有一個看起來像這樣的數據庫:是否有可能在生產規則中引用事實?

regular_player('Xi'). 
regular_player('Doyle'). 

expert_player('Houdini'). 
expert_player('Gandhi'). 

% don't allow expert players to be paired together 
start  --> good_pair. 
good_pair --> (player, expert) ; (expert, player) ; (player, player). 
player  --> ['Xi'] ; ['Doyle']. 
expert  --> ['Houdini'] ; ['Gandhi']. 

是否有可能從生產規則引用的事實,以消除重複我這裏。

回答

4

您可以消除事實並改用playerexpert規則。

或者,限定

player --> [P], { regular_player(P) }. 
expert --> [E], { expert_player(E) }. 

至於其做法是適當的是依賴於應用的。

+0

這是一個微不足道的例子,在實際的代碼中,我更喜歡原子在事實中,而不是生產規則,因爲它們將在別處使用。 – paxos1977

+0

@ paxos1977我同意。這將取決於應用哪種方法是理想的。 – lurker

相關問題