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 Logic.pm 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."
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.
Re:Excellent tutorial!
Dom2 on 2005-08-06T20:27:00
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.:-( -Dom
Re:Excellent tutorial!
Ovid on 2005-08-06T21:00:15
You might find an intro to Prolog and RDF of interest. It has a follow-up article which explains how to use RDF with SWI-Prolog.
Re:Excellent tutorial!
Ovid on 2005-08-06T21:04:23
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.
Re:Excellent tutorial!
autrijus on 2005-08-07T00:52:40
I especially like how Curry reuses all Haskell syntax, but managed to express the logical paradigm through it. The key seems to be thefree
variable annotation and the=:=
equivalence operator.In Perl 6, this might be:
my $x is free;
$x + 3 === 4;
say $x; # 1Does this seem sane to you? I wonder if P6L can handle this.
:-) Re:Excellent tutorial!
Ovid on 2005-08-07T01:48:31
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. From my interactions with others, I think this is a flat statement of fact.)
That being said, I have a bit of a reservation about your proposal. Assuming that my $x is free; means that $x is an unbound logical variable, does this mean that it cannot be assigned to? That would fit with the logic paradigm, but can cause confusion with programmers do not immediately see the distinction. Luke Palmer suggested a different method of declaring them (if I understood him correctly), whereby one would write $`x. The backtick after the primary sigil would indicate that this is a logical variable. Thus, this type information would always be readily apparent.
Also, you example gives me pause because math is, regrettably, one area where logic programming breaks down:
my $x, $y is free;
$x + $y === 2;
say $x; # ???Unless you can introduce constraints, the variables have infinitely many values with no upper or lower bounds to even reasonably start computation. Perhaps we can get a bit closer by adding traits and combining Luke's notation?
my int $`x but 10 > $`x > 0;
my int $`y but 20 > $`y > 10;
while $`x + $`y < 20 {
say "$`x + $`y === 2";
}And the append/3 predicate might become:
my @`x, @`y;
@`z = 1,2,3,4,5;
while (@`x, @`y) === @`z {
say "The append of @`x and @`y is @`z";
}That's awfully procedural, though, and I don't think it's what you're looking for.
Re:Excellent tutorial!
autrijus on 2005-08-07T18:30:11
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 freeTranslating this to Perl6:
Does this make some kind of sense?multi append ([], @ys) { @ys }
multi append ([*$x, *@xs], @ys) {
($xs, append @xs, @ys)
}
sub last ($l) {
my ($`x, @`xs);
append(@`xs, [$`x]) === $l;
$`x;
}Re:Excellent tutorial!
autrijus on 2005-08-07T18:46:38
Er, sorry, it should be@l
in thatlast
:sub last (@l) {
my ($`x, @`xs);
append(@`xs, [$`x]) === @l;
$`x;
}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...
Re:Excellent tutorial!
Ovid on 2005-08-07T19:10:20
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?
Re:Excellent tutorial! - could it all be one page
thickas on 2005-08-08T23:18:07
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 much.
Re:Excellent tutorial! - could it all be one page
Ovid on 2005-08-08T23:41:38
Try Print Preview. The slides are all on one page and it should print as one document. It's just Javascript that makes it look like multiple pages.
If you find yourself using logic programming for your code, let me know. I'd be curious to find more examples of how people are using it.
Re:Excellent tutorial! - could it all be one page
Ovid on 2005-08-08T23:44:45
I forgot to mention that I'm also preparing an article for the Perl Review. They'll get it first, but I'll own the rights and after it gets published, I should be able to distribute it with AI::Prolog (it will be a while, though.)
Re:Excellent tutorial! - could it all be one page
thickas on 2005-08-09T00:36:55
Das ist gut, c'est fantastiqueI can barely wait (@$work) to start reading it.
Thank you.