Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday May 17, 2008
08:59 AM

Pure Perl Logic Programming (no Prolog!)

[ #36452 ]

I decided to work on my logic programming module again today. I've eradicated lots of bugs (and probably found lots more). Here's a basic demo:

use AI::Perlog ':all';

my $data = AI::Perlog->new( { predicates => [qw/beautiful likes shiny/] } );

$data->add_facts(
    [qw/ beautiful people /],
    [qw/ shiny Firefly /],
    [qw/ shiny Kaylee /],
    [qw/ likes ovid whiskey /],
    [qw/ likes andy whiskey /],
);

# declare a logic variable
var my $stuff;
$data->add_rules(
    rule( 'likes', 'ovid', $stuff )
      ->if( [ 'shiny', $stuff ] ),
);

var my $what;
my $results = $data->query( 'likes', 'ovid', $what );

while ($results->next) {
    print 'Ovid likes ', $what->value, "\n";
}
__END__
Ovid likes whiskey
Ovid likes Firefly
Ovid likes Kaylee

Note how we're pulling data not just from the fact that 'ovid likes whiskey', but also from the rule 'ovid likes shiny stuff' and both 'Firefly' and 'Kaylee' are shiny stuff. Making logical inferences like this is what logic programming is all about!

It's not even close to being releasable due to lots of bugs and no documentation, though. For example, the append/3 predicate is horribly broken and there are lots of problems with undefined variables. There also appear to be problems in the backtracking engine.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Any thoughts on what it would take to tie an RDF triple store into AI::Perlog to provide some of the facts? Is it as "simple" as managing an iterator over the store?
    • Well, I've provided assert/1 and retract/1 predicates for AI::Prolog, so it I don't think that should be too difficult, so yeah, an iterator sounds pretty simple. But I'd only do that if you really need RDF. As cool as it is, being limited to triples and having no interesting data structures seems pretty limiting (though it does seem appropriate for the problem space).