Slash Boxes
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)

  (email not shown publicly)
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)

Friday June 05, 2009
03:28 AM

What's Not On the CPAN

[ #39076 ]

Because I've moved, I don't yet have 'net access at home and it appears that, for varying reasons, getting it is particularly annoying. As a result, I've been doing some work at home, but not uploading it to the CPAN or github. Basically:

package My::Database;
use AI::Logic::Database
  variables  => [qw{Person}],
  predicates => [qw{male/1 female/1 married/2 husband/1}];

male { 'frank' };
male { 'tony' };
male { 'bill' };
male { 'tom' };
male { 'alvin' };
female { 'sally' };
female { 'sarah' }:

married { 'frank', 'sarah' };
married { 'tom', 'alvin' };

Rule {
  husband { Person } =>
    male    { Person },
    married { Person, Any };

The syntax looks strange, but if you know Prolog, the above should look strange, but be familiar. To query it, issue queries with callbacks to handle successful queries:

use AI::Logic 'My::Database';

my $frank = Var 'frank';
male($frank, sub { print 'frank is male' });

my @males; # get all males
my $male = Var;
male($male, sub { push @males => $male->value });

my $is      = 'is not';
my $name    = get_some_guys_name();
my $husband = Var $name;
husband($husband, sub { $is = 'is' });

print "$name $is_husband a husband\n"'

Some of you may have noticed that 'alvin' will never be listed as a husband, but that's because I don't have disjunction ('or') figured out. I know how to do it, but I don't know the right syntax to make it obvious. For the time being, adding an additional rule solves this case (and is logically equivalent).

# handle the case of 'alvin'
Rule {
  husband { Person } =>
    male    { Person },
    married { Any, Person };

The cut operator (!) should be trivial to implement, but it will be the Cut keyword, and lists will eventually be added, at which point the system might even be vaguely complete. I doubt it will be fast, but I suspect it will be a heck of a lot faster than AI::Prolog. If I'm really, really lucky, it might even be fast enough for some production work (I've a few optimizations in mind, but I've no intention of implementing any until I have more work done on this).

This is a generalization of Adrian Howard's continuation-based logic solver.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.