My Gripes with Prolog

28 points by hwayne


tef

prolog, the language that makes parsers easy to write, and string handling impossible

you may enjoy exploring languages like griswold's icon, where goal directed evaluation remains, but it's far more imperative in flavour!

aarroyoc

As a Prolog enthusiast and occasional Scryer Prolog contributor, those are all fair points. Many of them have been corrected in specific dialects of Prolog, but there's no consensus to bring to the ISO standard (which I don't know if you are aware, but last year had an update to add DCGs!). Strings, data types, functions and even the sort/2 predicate have bite me in the past.

Regarding cuts, I've seen that many problems can be solved by using reified predicates and dif/2. dif/2 was present in the earlier versions of Prolog, but was replaced by the current /= later for performance purposes probably, but the Prolog designers already knew it wasn't as clean as dif/2. Reified predicates on the other hand allow us to express many more things in a clear, monotonic and bidirectional way but it's like programming in a higher layer and it is more verbose than "obvious" Prolog.

dkl

I believe foo(A, B) is failing when called without instantiations because A = B will definitely succeed in all cases except where A and B are already ground terms with different values. The only time A = B at the query prompt will fail is if A and B are already instantiated to different values. What you want here is dif(A, B) instead of \+ (A = B), which is non-standard but I think most Prolog's provide it. Notice that the query dif(A, B), foo(A, B) will succeed.

Remember that =/2 in Prolog is neither assignment nor an equality test, it is unification. It acts like assignment and equality under many ordinary-looking circumstances but in fact it is sort of the whole engine of Prolog in general.

Also you might enjoy using findall/3 instead of bagof/3 since it will only ever produce one result. I consider bagof/3 and setof/3 to be more useful because you can do things analogous to SQL GROUP BY but they are harder to use correctly than findall/3 because of this.

Prolog is old and has a lot of warts; the ones you enumerated are real, but (to me) they are just historical stumbling blocks we all trip over at the beginning.