In order to have AI::Prolog useful and not a toy I have to return data structures instead of pretty-printed strings and I have to have math. The data structures now appear to work. After a few more attempts to break it, I might upload it. I might also decide to rework the resulting data structures. Math will be next (I hope).
After that, I really need syntactic sugar for creating the logic programs and the database. Having to know Prolog is a major drawback no matter how simple Prolog is. I'll also have to look at performance. Unfortunately, I may have to tackle performance first because the syntactic sugar will likely involve direct hooks into the data structures rather than targeting the Prolog language. This allows me to skip the Parser object entirely but I don't fancy doing performance tuning prior to the sugar. Regrettably, I can do the sugar first if I target the Prolog interface instead of the underlying engine but if I do that I may have to rewrite the sugar interface later.
Now that I stop to think about it, if I just target the Prolog interface with the sugar, this may be sufficient as parsing the Prolog is not the bottleneck. Unification and backtracking are the bottlenecks. I may just have to start converting the data structures to something that is "C" friendly and start using Inline::C. I really don't believe I can achieve the necessary performance otherwise. I'm running about 1000 LIPS and that's comparable to other HLL Prolog implementations, but that's not fast enough to do complicated work. In the early 90s, that would not have been great, but it wouldn't have been too horrible, either (serious Prolog engines were running between 10,000 and 100,000 LIPS back then.) Good Prolog engines today are measuring performance in MegaLIPS. I know I can easily improve on 1000 LIPS with pure Perl, but not to point of MLIPS.
I also worry about whether or not the new interface is useful.
use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 0; use AI::Prolog; my $database = <<'END_PROLOG'; append([], X, X). append([W|X],Y,[W|Z]) :- append(X,Y,Z). END_PROLOG my $logic = AI::Prolog->new($database); $logic->query('append(X,Y,[a,b,c,d]).'); while (my $result = $logic->results) { # do stuff with $result; }
The successive values of $result are (nicely formatted so you can see what's going on):
[ 'append', [ ], ['a','b','c','d'], ['a','b','c','d'] ], [ 'append', ['a' ], ['b','c','d' ], ['a','b','c','d'], ], [ 'append', ['a','b' ], ['c','d' ], ['a','b','c','d'], ], [ 'append', ['a','b','c' ], ['d' ], ['a','b','c','d'], ], [ 'append', ['a','b','c','d'], [ ], ['a','b','c','d'], ]
I actually created a AI::Prolog::Result object that would bind X and Y to their successive values, but for a variety of reasons, I wound up not using it. Maybe I'll try again.
I think I am beginning to get the tiniest glimmerings of the pain that Larry and Co. must put up with on a routine basis.
Prolog's interface always was an issue, yours can't be worse!
Somehow, I'm not sure any of my old Prolog 5.25" floppies is still readable, so I may not be able to dig up any test programs
Re:Prolog
Ovid on 2005-01-30T21:35:40
Well, I just uploaded
.04 (it will hit the mirrors in a few hours) and it's definitely better than it was. However, Salvador Fandiño has said today on the Perl AI list that he will fix Language::Prolog::Yaswi to work with the 5.4 versions of SWI-Prolog (5.5 has to wait due to Unicode problems) and he said he will happily accept patches to improve his tests and docs. This is great news. I'll still work on mine because now I've made promises I need to keep, but his is a much faster and more robust implementation.