6 ms·
I studied Prolog in college (3rd CS year course, 2003). I concluded it didn't deliver on its promise. The promise was that, as in the article, you 'Say what y
by feral 10y ago
I studied Prolog in college (3rd CS year course, 2003).
I concluded it didn't deliver on its promise.
The promise was that, as in the article, you 'Say what you want, not how you want it done.'
In practice, once you start writing non-trivial programs, you run into situations where they take ages to run, as Prolog does its search in the background.
So, you have to start using all these languages features to control and optimize the search, such as: https://en.wikipedia.org/wiki/Cut_(logic_programming) https://en.wikipedia.org/wiki/Cut_(logic_programming)
And you end up spending a lot of time reasoning about the how that it said you didn't have to care about.
I concluded that, as a result of performance issues, the core Prolog abstraction 'leaks' too frequently for it to be worthwhile. (https://en.wikipedia.org/wiki/Leaky_abstraction https://en.wikipedia.org/wiki/Leaky_abstraction)
Its a great promise, if a smarter language or implementation could achieve it, but overall I concluded that if I was going to have to spend all this time reasoning about the how anyway, I might as well just deal with that up-front, rather than after-the-fact.
I'd love to hear a contrasting opinion (I got pretty good at it, but only over months, not years, of use). But I suspect this is the reason why Prolog didn't make it. It looks good at the start, but it doesn't deliver.
- lmkg 10y agoIMHO, Prolog is the leading example of a language you learn for the brain-twisting, and not for actual usage. Even moreso than Lisp. Full-blown end-to-end Prolog programs in production are vanishingly rare, and for good reason. But much more useful are the Prolog-inspired chunks of code dealing with a separable part of a larger problem. Logic-based programming is an appropriate tool for some problems, and it can be applied even in the context of procedural (of course, it's easier in languages that support DSLs). As an example, clojure's core.logic seems to be pretty popular and that's basically just a subset of Prolog. Somewhat counter-intuitively, Prolog-inspired DSLs tend to more straightforward because they're missing some of the advanced features that Prolog needs to make it usable. The DSL can rely on the host language to do some of the dirty work for it.
- mondoshawan 10y agoActually, less than you might think. The Android OTA recovery environment is written in prolog, last I remember.
- gavanwoolery 10y agoIn my opinion, Prolog is a horrible programming language. BUT... The idea of logical programming has much promise. Not for programming, but for running queries on a knowledge base. In fact, unification / lambda calculus is arguably the only way you can make complex logical deductions without a brute force approach (you could also use machine learning, but that would not scale for queries with many variables). The only problem is, the domain in which this is useful is fairly small, and requires an explicitly defined knowledge base, whereas things like machine learning are very flexible and cover a broad variety of domains pretty well. One area I think it holds promise for is in games - imagine characters being able to make deductions about the world around them, and react appropriately - beyond things like behavior trees (which also do not scale once you have many complex rules interacting). So...in my opinion it is a little bit like SQL. You would not use SQL to write an application (I hope!).
- qohen 10y agoThe idea of logical programming has much promise. Not for programming, but for running queries on a knowledge base. You might want to take a look at Datalog [0]: Datalog is a declarative logic programming language that syntactically is a subset of Prolog. It is often used as a query language for deductive databases. In recent years, Datalog has found new application in data integration, information extraction, networking, program analysis, security, and cloud computing. An example of this in real-world use would be in Rich Hickey's Datomic [1]: Datomic is a distributed database and implementation of Datalog on Clojure. It has ACID transactions, joins, a logical query language—Datalog. [0] https://en.wikipedia.org/wiki/Datalog https://en.wikipedia.org/wiki/Datalog [1] https://en.wikipedia.org/wiki/Datomic https://en.wikipedia.org/wiki/Datomic
- e12e 10y agoI've tried to get started with datablog a few times, but haven't yet been able to find a useful, Free/open software system that seems practical and has a good practical/hands-on tutorial? I'm thinking there ought to be something with usefulness comparable to sqlite or at the very least Berkley DB? But I've yet to find it.
- 10y ago
- sirodoht 10y agoThe question is though: had we invested all that time and money of imperative programming and object-oriented, in Prolog too, would it still be the case of not delivering? Do we include in our thinking the full potential of the language? I am thinking this is what happened with functional programming too. Only lately we understand its true potential, starting with some functional concepts in Python and JavaScript in the early and mid 90s and continuing with ES6, Rust and Swift.
- ced 10y agoThere has been quite a lot invested in Prolog and its successors. Eg. https://en.wikipedia.org/wiki/Fifth_generation_computer https://en.wikipedia.org/wiki/Fifth_generation_computer It's just fundamentally much harder to get anywhere than with procedural languages.
- YeGoblynQueenne 10y ago>> It's just fundamentally much harder to get anywhere than with procedural languages. It's harder to learn than procedural languages. Once you know what you're doing it's much easier to get anywhere with it.
- ced 10y agoI meant that designing and implementing good declarative logical languages is an open research problem, because logical inference is basically unsolved. Procedural languages are trivial, in comparison.
- YeGoblynQueenne 10y agoLINQ and the C# compiler (with pattern matching proposals in 5.0, I think, but not yet implemented) is inching closer to some of Prolog's ideas. In that sense there is a bit of a risk of implementing a "buggy, slow" Prolog in the process of re-inventing its wheels.
- romanows 10y agoSame thing happened to me, also right when I encountered "cut". However, rather than considering Prolog a leaky abstraction, I started thinking of it as a concrete implementation of a particular kind of useful search algorithm. If you learn how the core algorithm works, you can use it in the same way you'd use a regular expression library to solve particular types of problems.
- dkarapetyan 10y agoThis is the correct approach. It excels in certain domains. If you need something that is suspiciously close to some kind of rule engine then prolog is the way to go.
- YeGoblynQueenne 10y ago>> If you learn how the core algorithm works, you can use it in the same way you'd use a regular expression library to solve particular types of problems. Aye, very good advice- also, keep in mind Prolog is essentialy Turing-complete pattern-matching, so like regular expressions but with the ability to describe any program you can hope to compute (and, er, some you can't- see infinite recursion).
- danieldk 10y agoIt looks good at the start, but it doesn't deliver. I think that it depends on the domain. Part of my PhD project was making a natural language generator for a Dutch grammar/lexicon. The grammar was developed for a high-coverage parser. Due to Prolog's declarative nature, the grammar, lexicon, and productive lexicon could be used with very few changes. (E.g. in productive lexicon, for parsing one would derive a root and lexicosyntactic information. In generation, you start with a root and underspecified lexicosyntactic information and derive a word with its full lexicosyntactic information.) One could argue that Prolog was primarily used for data (grammar rules, lexicon). And it is true that people have developed systems that target unification grammar specifically. But in this domain, Prolog gives you a good local optimum: feature structures are trivially converted to Prolog terms, feature structure unification becomes Prolog term unification, Prolog's metaprogramming facilities make it easy to compile/rewrite grammar rules (e.g. in order to exploit first-argument indexing in particular scenarios). That said, I didn't and wouldn't use Prolog outside that domain and haven't written Prolog since. Also, I think Prolog has serious deficiencies, e.g. it can be quite tricky to write good steadfast[1] predicates. [1] http://permalink.gmane.org/gmane.comp.lang.swi-prolog.general/3987 http://permalink.gmane.org/gmane.comp.lang.swi-prolog.genera...
- YeGoblynQueenne 10y ago>> One could argue that Prolog was primarily used for data (grammar rules, lexicon). Weeell, more to the point: in Prolog data is your program so anything you do is data manipulation (or program execution, depending on how you choose to think about it).
- YeGoblynQueenne 10y ago>> The promise was that, as in the article, you 'Say what you want, not how you want it done.' That is the promise of declarative programming, in general. Prolog is a logic programming language that is also declarative. Its primary "promise", insofar as it makes any promises, is to allow the use of first-order logic as a programming language. In that, it delivers in spades, more so than any other language (and even other logic programming languages are largely based on Horn clauses). The reason Prolog is held up as an example of declarative programming is because it's one of the best realisations of that paradigm- or in any case it's one of the few such languages one can do actual programming in (as opposed to, say, xml or html). Prolog's name however stands for "PROgrammation en LOgique", not "PROgrammation DEclarative". In that sense it's pretty unfair to blame Prolog for not being a perfect declarative language, or for not keeping any other promises it never made.
- posterboy 10y agoWell, if you didn't say how you want it, you can't really complain how slow it is either. I was under the impression it's slow all along, but it might have other merrits, especially for a student rather than an enterprising dev.
- YeGoblynQueenne 10y agoProlog was slow in the '60s. Not anymore [1]. It is, after all, an in-memory, No-SQL database. Even "slow" ish Prologs are pretty fast these days [2]. If your program is running slowly you need to take care with the way you've written it, but that's true for any language. It's more the case with Prolog and it's harder to optimise because it's harder to get your head around it, but beyond that, it's not "slow" in any sense of the word, particularly when you take into account what it is that it does. [1] https://www.dcc.fc.up.pt/~vsc/Yap/ https://www.dcc.fc.up.pt/~vsc/Yap/ [2] http://www.swi-prolog.org/pldoc/man?section=jitindex http://www.swi-prolog.org/pldoc/man?section=jitindex