4 ms·
>> Also, the language is not really well suited for that; if I have to specify how exactly in which order the calculations need to be made, then imperative lang
by YeGoblynQueenne 9y ago
>> Also, the language is not really well suited for that; if I have to specify how exactly in which order the calculations need to be made, then imperative languages are a much better tool. I'm throwing away all the advantages of Prolog if I have to do this all the time - and in practice I do.
I'm going to kindly ask you to give at least a couple of different examples of this, because it's another of those criticisms of Prolog that have no real basis in actual practice of programming in the language.
My source for that is that I've been programming all my side projects and two dissertations in Prolog since 2007 and I've never been in a situation where I had to think long and hard about how to order my predicates. Most of the time the correct ordering is pretty straight-forward.
This criticism, about ordering of clauses, has its historical root in the competition between Prolog and PLANNER - because in PLANNER predicate order did not matter, which made the language more "pure" but also less efficient (which in turn is why many fewer people have heard of PLANNER than have heard of Prolog). The real point about it is not that you may have to pull your hair out a couple of times while programming. The point is that in first-order logic, as in maths, predicate order doesn't matter and therefore, in a pure first-order logic language, it shouldn't matter either. The criticism is that Prolog lacks purity, in other words.
Which, if I may be so bold, is nonsense on stilts. The real world is not pure and you can't has purely anything languages. People who complain about Prolog's lack of purity are quite prepared to throw away the baby of a very useable, 99% declarative language, allegedly because the bathwater of the missing 1% is really messing their codes up. I'm just not convinced by that to be honest.
- tom_mellior 9y agoBe fair! There are many unfair criticisms directed at Prolog in this thread, but this one does have a basis in fact. You'll admit that there are huge practical differences between ancestor_of(P, P). ancestor_of(A, P) :- ancestor_of(A, Parent), parent_of(Parent, P). and ancestor_of(P, P). ancestor_of(A, P) :- parent_of(Parent, P), ancestor_of(A, Parent). You're right that "in actual practice" of someone who has been programming Prolog for ten years, "the correct ordering is pretty straight-forward" in many cases. But that doesn't mean that the order doesn't matter! It just means that you are experienced enough, and you have no problem with the fact that you have to specify the order.
- YeGoblynQueenne 9y agoWell, I didn't say that clause ordering doesn't matter! Of course it matters. And yeah, left-recursion is a pain (because depth-first search etc). What I'm saying is that in principle this may be a problem for purists, but in practice it's no big deal. I don't think it has much to do with experience, or at least you don't need to be an advanced user to be aware of how clause ordering affects your results. So, yes, you need to understand a few things about how the language works before you can program anything non-trivial, but that's true for any language, isn't it? Critics, mostly in the past, latched on to the few niggling non-declarative impurities like this to write off the entire language as "not truly declarative" when there isn't really anything usable that's closer to the ideal. Talk about binary logic... Edit: Glad to see another user around here btw. Check out my new library. Just finished it and am looking for eyes on :) https://github.com/stassa/indexed_terms https://github.com/stassa/indexed_terms
- tom_mellior 9y ago> Well, I didn't say that clause ordering doesn't matter! The OP complained about "[having] to specify how exactly in which order the calculations need to be made", and you said that this complaint had "no real basis in actual practice" and "I've never been in a situation where I had to think long and hard about how to order my predicates". You did kind of dismiss their criticism. BTW, you keep talking about clause ordering, where goal ordering within clauses is the more difficult issue, I think. > I don't think it has much to do with experience, or at least you don't need to be an advanced user to be aware of how clause ordering affects your results. Based on my experience as a teaching assistant in a Prolog univesity course for a few years, I would say that it does have to do with experience, and beginners often get clause and goal order wrong. It's true that soon they become aware that ordering affects the behavior of the program, but they often don't understand how it affects the program, so they semi-randomly reorder things until they find a permutation that seems to work. > So, yes, you need to understand a few things about how the language works Yes! But we collectively haven't figured out how to teach this well, and many people are left with a terrible first impression of Prolog and don't continue to a point where they understand enough to be effective. > Check out my new library. From the Readme it looks nice. I think iterm_value/3 should maybe be called iterm_nth/3, which is more idiomatic. Also, since you mention GNU Prolog's array library, maybe also add if your interface is compatible with it, and if not, why not? I think more standardization of libraries across implementations would be better for the Prolog community than more fragmentation.