Wow, now this was a long week. Actually, it was more like a month with Christmas and the lack of motivation, to get me through this chapter.
Why did it take so long? I’ve never programmed in a logical programming
language but I have to admit, not being too thrilled about Prolog. Logic
programming is kind of a one-trick pony for me and while it is fun to let it
solve a sudoku for you, it is not being efficient at that but rather dumb. If
you want to optimize a Prolog program you have to use sophisticated operations
at which point it does not really seem straightforward and requires more
intricate knowledge of Prolog. Also, debugging is awful, you just get ‘no’ as
response. Supposedly one can use trace
to debug, but I haven’t investigated
further.
While I suppose Prolog was the most annoying part, the reward level was on par with Io. Once my stupid solution worked, I was jumping around happily. As an example, day 2 has the homework to implement a sorting algorithm in Prolog, here’s my take on Mergesort:
The hardest part by far was the splitlist
function, as I really struggled how
to express it properly. In the end, I needed a friend to help me and even now I
am not completely sure what exactly was wrong with my previous, non-working
solutions. The rest of the functions were rather easy.
During this “week” me and my friends had a number of gripes with Prolog: I
personally don’t like the syntax very much, especially that defining new facts
in the REPL requires assert
and couldn’t be done with fact(a, b)!
or
something similar. Another problem is that predicates are not first-order, that
is, you can’t parametrize things nearly as nice as in about any other language
by just passing “functions” as arguments.
Fun fact: the Prolog stats are completely invalid, since Prolog and Perl
share the file extension .pl
(also in Vim), therefore four of the five most
forked repositories in the stats are not even Prolog. Popularity wise, Prolog
is way lower in reality than #21 on GitHub would suggest.
In the end, I was quite disappointed in the Seven Languages-book chapter on Prolog, I had some trouble expressing things in Prolog afterwards and, well, the solution to Sudoku presented there seemed kinda lame: “well, let’s get these predefined predicates from GProlog and put them together”. Yeah, it is understandable, but the GProlog predicates do all the magic.
Will I be continuing Prolog? Probably not except for the occasionall dabble. It seems to me too limited for real usage and I get annoyed too fast with it. Logical programming on the other hand might be worth investigating further, maybe with Oz or Mercury or even Clojure’s core.logic.