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 ]

Journal of jjore (6662)

Tuesday January 02, 2007
03:24 PM

Thinking about embedding constraints in perl

[ #32050 ]

I'd like to integrate a logic engine into normal imperative perl with some reasonable ergonomics. This is all sugar for getting to AI::Prolog. It's just an experiment with myself about how to allow normal code to use the benefits of logic programming.

The primary benefits I'm interested in are abstracting away the search code, parameterizing the search strategy, and simplicity of maintenance.

A package may have a database of rules, variables, bindings, whatever. It's just a package variable or something like that.

Logic variables get tied because they were tagged with an attribute like :Logic or something. Interacting with the variables means assertions get stored or tested in the database.

I'm in the middle of learning Mozart which does this kind of thing and then I probably ought to go learn how Mercury parameterizes its search strategies.

package Somewhere;
# Hoist 'RULES' block to be executed like BEGIN or similar
RULES {
    # RULES GO HERE
    $bar == $foo;
}
 
sub foo {
    $bar = 42;
 
    RULES {
        # These rules are present for this scope?
        $baz == $quux;
    }
 
    return $foo; # returns 42
}

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.
  • Part of the reason I'm glad that they didn't try to shoehorn logic programming into Perl 6 is the following:

    father(jim,bob).
    father(bob,sean).
    mother(alice,bob).
    mother(alice,mary).
    mo ther(mary,sally).
    parent(P,C) :-
        father(P,C);
        mother(P,C).
    siblings(S1,S2) :-
        parent(P,S1),
        parent(P,S2),
        S1 \= S2.
    cousin(X,Y) :-
        parent(P1,X),
        parent(P2,Y),
        siblings(P1,P2).

    Now ask any version of Prolog who cousins are:

    ?

  • I forgot to mention that, ignoring everything I wrote above, I'd still love to see this!