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)

Saturday August 06, 2005
02:31 PM

How the presentation went

[ #26146 ]

Short description: I was very pleased.

I've now posted the conference version of the Logic Programming in Perl presentation. There were more people there than I expected and, much to my surprise/horror, Larry, Damian and Luke were sitting in the audience. Apparently, there's still a strong interest in how to bring logic programming to Perl 6.

At the beginning of the talk, there weren't too many questions. I think there are two reasons for that. First, I explained things well enough that when I was pointing out some of Prolog's advantages over Perl, it was extremely clear and everyone understood. Second, I suspect many folks in the audience were thinking "yeah, Prolog handles that better, but I still don't know how I would use it."

The second half of the talk dealt with lists in Prolog and when I finally got to the part where I showed the power of append/3, I saw a number of smiles and nodding heads. Maybe they didn't know how to use it, but they were impressed. Then when I asked for questions, Damian raised his hand. I said "Yes Damian? ... Oh, God." That got a good laugh and Damian had a bit of fun with it, but I knew that if anyone could hit me with a tough question, it would be Damian. Instead, he asked about what it would take to integrate logic programming and Perl 6 (I can't recall his exact question.)

I wasn't certain of the best way to answer that. Underneath the hood, do you want a WAM? Can you hook into the rules engine? In the actual code, how do you make thing distinct enough that folks know they're using declarative code instead of imperative/OO/functional code? I speculated that one might need a way of declaring logic variables and possibly new keywords for declaring facts, (logic) rules and queries. Unfortunately, I couldn't think of much more on the fly. I'm not sure if it was Larry or Damian who asked if I thought Perl 6 had rich enough semantics (features?) to support it and I replied "yes." At the very least, slapping on a new grammar that hooks into a module could handle much of this. And that's where AI::Prolog comes in.

In the development version on my hard drive, I've finally completed the decoupling of the parser from the rest of the code. What that means is I can theoretically do something like this:

use AI::Prolog qw/:std/;

predicate 'append';          # declare predicates
var \(my ($W, @X, @Y, @Z));  # declare logic variables

# append([], X, X).
append = fact( [], \@X, \@X );

# append([W|X], Y, [W|Z]) :- append(X, Y, Z).
append = rule(cons($W, \@X), \@Y, cons($W, \@Z)) =>
           sub { \@X, \@Y, \@Z });

# append(X, Y, [1,2,3,4]).
while (append(\@X, \@Y, [1,2,3,4])) {
    print @X, @Y;

Obviously, that's just "thinking out loud" and is rather ugly. I can wrap new front ends on AI::Prolog and allow people to experiment with different styles and I would like to figure out what a "clean" style might entail.

Luke Palmer and I were chatting in my apartment about this problem and he's thinking about it from the Perl 6 standpoint. He had some fascinating ideas, but I'm hardly qualified to really think about things from a Perl 6 standpoint. While this is more important than Perl 5 (since it has a chance of being integrated directly into the language), I'll focus on a clean syntax that can be implemented now. Suggestions welcome.

Another questioner asked me a couple of times how she can use this in her applications. Despite my explaining at the beginning of the talk that this was about a different way of looking at programming and not about tools you can use today, I was still asked that question. The problem is there's no "good" answer. You can ask me how you can use object-oriented programming in your code and I still can't answer it. You have to understand OO code and your particular needs to appreciate how OO might be appropriate. It's the same with Logic programming. Until you understand how logic programming works and what your particular needs are, it's impossible to say "hey, a little first-order predicate calculus restricted to Horn clauses is just what I need here."

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.
  • Thanks for journaling about this so I can read it from afar. Very good slides.

    This has motivated me to install the Münster Curry compiler [], a Haskell implementation of the Haskell-Prolog hybrid language Curry [].

    I suspect it'll be a lot of fun reading about it. As for application programming, it seems that much of the semantic web stuff -- RDF in particular -- corresponds closely to logic programming models, so that might be a good vector to explain to people.

    • I suppose a comparison to the semantic web might help some people. But I'm still banging my head at Practical RDF [], with little success. Some ideas just don't seem to want to fit in my head. :-(


    • I'm glad you liked the slides. I've been hearing a bit about Curry and I should dig into it. Incidentally, you may be interested in the response I just made to Dom. I list a couple of Prolog/RDF links which may prove interesting.

      • I especially like how Curry reuses all Haskell syntax, but managed to express the logical paradigm through it. The key seems to be the free variable annotation and the =:= equivalence operator.

        In Perl 6, this might be:

        my $x is free;
        $x + 3 === 4;
        say $x; # 1

        Does this seem sane to you? I wonder if P6L can handle this. :-)

        • Well, there does seem to be a strong desire to get logical programming into P6, so I suspect that well-thought out proposals will be welcomed. The major problem I have in participating is two-fold. First, I simply don't have the experience with P6 to be able to make contributions that are going to fit well in the current model. Second, I fear that most who are involved are considerably brighter than I am. This makes me a poor sounding board for ideas. (I'm not trying to present this as false modesty.

          • I like the ` twigil -- the is free syntax is from Curry, but I think twigil fits Perl6 better.

            To define last with append in Curry, we write:

            append [] ys = ys
            append (x:xs) ys = x : append xs ys

            last l
                | append xs [x] =:= l
                = x
                where x, xs free

            Translating this to Perl6:

            multi append ([], @ys) { @ys }
            multi append ([*$x, *@xs], @ys) {
                ($xs, append @xs, @ys)
            sub last ($l) {
                my ($`x, @`xs);
                append(@`xs, [$`x]) === $l;

            • Er, sorry, it should be @l in that last:

              sub last (@l) {
                  my ($`x, @`xs);
                  append(@`xs, [$`x]) === @l;

              The trick of Curry is to introduce a special type, Success, that encapsulates constraint solutions. I'm still working through the tutorial [], so it will take a bit before coherent thoughts emerge...

            • OK, I'm definitely liking this better. I think it can work. Is multi enough, though? Would assert or something similar be a better keyword so Perl can know that it's working with a fact or rule?

    • Thank you very much for the excellent slides about a topic that I share your excitement about.

      Is it possible to have the slides published as PDF or a single HTML page, so I can print them and read them/attempt to understand them ?

      I expect there are probably a lot of good reasons not to (maybe I should download the modules instead), but having the ability to do some logic programming in Perl would be cool beyond comprehension (caveat knowing when to use, caveat backtracking cost etc).

      Thank you very mu