Search code examples
prologdcg

Is it possible to reference facts in production rules?


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 reference facts from production rules to eliminate the duplication I have here.


Solution

  • You could just eliminate the facts and use the player and expert rules instead.

    Or, define

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

    As far as which approach would be appropriate is application dependent.