7 ms·
The fact that you need to understand the execution model is not a limitation or an accident: it's a feature. One of the aims of prolog is to PROgram in logic. T
by felixyz 3y ago
The fact that you need to understand the execution model is not a limitation or an accident: it's a feature. One of the aims of prolog is to PROgram in logic. There are plenty of other logical frameworks that you can use to formulate a problem, make deductions etc, but then what do you do? The point of Prolog is that the operational and declarative semantics concur (excuse the non-exact verbiage). People mistakenly think this means there shouldn't be an operational semantics, or that it's a failure if you have to learn about it. If that's what you need, Answer Set Programming (or SMT solvers etc) might be a better fit. But that's not what Prolog is aiming to be.
- usgroup 3y agoI’m not sure it’s a feature that you MUST think about the execution model even for trivial things :-) but that you can and should is certainly a strength.
- felixyz 3y agoIt's really not different from any other programming language, I think Prolog is just held to a higher standard, and I think that might be due to a misconception. Also, XSB Prolog and SLG resolution[1] should be mentioned. It solves some of the problems with Prolog that force you to think about the execution model when you'd rather not. To some extent, this can be thought of as getting the good parts of both Datalog and Prolog. SLG resolution was introduced in SWI-Prolog as well fairly recently[2]. [1]: https://www3.cs.stonybrook.edu/~sbprolog/manual1/node2.html https://www3.cs.stonybrook.edu/~sbprolog/manual1/node2.html [2]: https://www.swi-prolog.org/pldoc/man?section=tabling https://www.swi-prolog.org/pldoc/man?section=tabling
- ghusbands 3y agoJust try writing (without hacks/cuts) a run-length encoder that produces only one answer ([9,9,9,8,8,7] -> [[9,3], [8,2], [7,1]]) and works forwards and backwards and then tell me the execution model is not a limitation. It's the sort of thing where people produce versions that seem to work, but fall into infinite loops or inconsistent extra outputs if you go past the first answer. I'm not sure it's actually possible without meta-programming.
- convolvatron 3y agoI think aggregates help here by allowing you to take one answer, or take the best. But in general absolutely
- YeGoblynQueenne 3y ago>> Just try writing (without hacks/cuts) a run-length encoder that produces only one answer ([9,9,9,8,8,7] -> [[9,3], [8,2], [7,1]]) and works forwards and backwards and then tell me the execution model is not a limitation. But, why not use the cut? It's a feature of the language and it's there exactly so you don't have to bust your head trying to find a way to do things the hard way. I honestly don't understand what's the fuss with the poor cut. If you want an efficient language that runs on a computer then you have to be pragmatic and recognise that concessions have to be made to accommodate the limitations of the hardware. If you want something pure and ideal, then you should probably not be trying to do that on a computer. You should probably not be trying to do it at all. There are no pure formal systems, or if there are, we can't explain or understand them because they can't communicate with the external world (hey, no side effects, OK?). See Haskell, for instance. The article above says something really strange about Haskell, that it: >> ... finally broke through the wall of pure-functional programs being seen as ivory-tower languages that were impractical, or at least really awkward, for any system that needed to do I/O or interact with users Which to me is insane. I think it's talking about monads. Monads, as an escape from the ivory tower, impractical, or at least awkward formalisms of... what, LISP? I mean for the love of dogs. Prolog is a balanced language. People complain about it because it's not unbalanced, that's the problem. If it were 100% declarative and nobody could program anything in it, it would have legions of dotting admirers praising it for its perfection, and whining because they have to do all their work in languages that are hardly 10% declarative, like Rust, or Python or Ruby (and I'm being generous). People have to get their head around this: our computer science is primitive and it is full of holes, dark pits of despair and undecidability, intractability, and terminal inefficiency. To be practical, a language has to give up a little part of its true, pure self, that it could achieve in a perfect world. So Prolog has the cut, and you can use it to control its backtracking, which you need because it's implemented as a depth-first search, because that's efficient and convenient. So use the cut, it's a feature.