It works

Ovid on 2005-01-18T06:28:32

There will be a lot of work before I can finally get this ready for the CPAN, but this works (and it's pure Perl):

#!/usr/local/bin/perl

use strict;
use warnings;
use lib './lib/';
use aliased 'AI::Logic::Parser';
use aliased 'AI::Logic::Term';
use aliased 'AI::Logic::Engine';

my $parser = Parser->new(thief_prog());
my $term   = Term->new($parser);

my $engine = Engine->new(
    $term,
    Parser->consult(
        thief_prog(),
        {},
    )
);
print $engine->run;
print $engine->more;

sub thief_prog {
    return <<'    END_PROG';
    steals(PERP, STUFF) :-
        thief(PERP),
        valuable(STUFF),
        owns(VICTIM,STUFF),
        not(knows(PERP,VICTIM)).
    thief(badguy).
    valuable(gold).
    valuable(rubies).
    owns(merlyn,gold).
    owns(ovid,rubies).
    knows(badguy,merlyn).
    END_PROG
}

My long-term plan is to make the Prolog part optional and simply allow writing normal Perl with an optional Prolog interface for those who want to play with the language.