Can facts be referenced in production rules?

Let's say I have a database that looks something like this:

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'].

Is it possible to refer to facts from production rules to eliminate the duplication that I have.

+4
source share
1 answer

You can simply rule out the facts and use the rules playerand expert.

Or, define

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

How appropriate the approach is depends on the application.

+4
source

Source: https://habr.com/ru/post/1681493/


All Articles