3 ms·
Prolog is a terrible "programming language" - and I would never try to use it as such. But it is (at least conceptually) an excellent query language. In that
by gavanwoolery 7y ago
Prolog is a terrible "programming language" - and I would never try to use it as such. But it is (at least conceptually) an excellent query language. In that regard, it is much closer to SQL, as is its domain of reasonably applicable problems.
Clarification: I dont actually think prolog is terrible (I credit it as the most exciting language I have ever learned), I just mean its not intuitive to "program" with in the imperative sense of telling a computer what to do. What I mean by it is excellent as a query language is - given a set of data, it is great for drawing conclusions from that data (but not in the same way as a "traditional" query language like SQL).
- archgoon 7y agoHey; that sounds intersting; can you give an example of how you use Prolog in a SQL like context? How do you setup your 'DB'? How large does it scale?
- fiddlerwoaroof 7y agoYou might look at how datomic or datascript use a limited subset of prolog (datalog, with a lispy syntax) to express queries: you end up doing things like: [[?person :name “Bob”] [?person :state :tx]] To query for “the person named Bob who lives in Texas”
- fiddlerwoaroof 7y agoThe Clojurescript web framework fulcro uses this also for the sorts of things graphql is used for.
- jcranmer 7y agoI've used Datalog (which is essentially a stripped down version of Prolog) in the past for a pointer analysis. Essentially, you literally print out the inference rules and then the basic facts to a text stream, and then you use interactive queries on the text stream.
- muydeemer 7y agoYou might find https://github.com/graknlabs/grakn https://github.com/graknlabs/grakn of interest. Datalog was one of our main sources of inspiration. The query mentioned in this thread (the person named Bob who lives in Texas) would be something like: $x has name 'Bob'; ($x, $y) isa lives; $y has name 'tx';
- YeGoblynQueenne 7y agoProlog is not a good language for querying databases (if that's what you mean by "query language"). Foe one thing, it lacks a SELECT statement or list comprehensions and the like. If you want all results of a goal, you have to use one of the bagof/setof/findall predicates, or roll your own. On the other hand, Prolog programs are logic theories (as are Prolog queries) and their executio is a proof. The range of programs that can be expressed in Prolog is the set of programs that are computable by a Turing machine. So yes, Prolog is a programming language. Whether it's "terrible" or not is up to personal taste. I mean, I don't konw of an objective measure of what makes a programming language "terrible".
- gavanwoolery 7y agoagree with you - added clarification to my original comment :)
- guicho271828 7y agobagof/setof/findall ARE indeed list comprehensions, aren't they
- marcosdumay 7y agoSoftware has evolved on a direction where sending sets around is natural. That is no evidence that sending theorems around is problematic, it's just that current communication implementations happens to be very data-friendly and logic-unfriendly. There is probably a very human reason for that, but mathematically both representations are perfectly replaceable.
- segmondy 7y agoTerrible programmers often get defeated by Prolog. If you can't bend Prolog, don't blame prolog, blame yourself. :D
- gavanwoolery 7y agoI like Prolog, I just think that trying to use it as a traditional programming language for an average task is like using a sponge to bail water out of a boat - you can do it, but it is hardly the most effective tool. :) That said, there are very specific problem domains in which Prolog excels.
- alfiedotwtf 7y agoYou may also want to check out Mercury: https://www.mercurylang.org/
- tluyben2 7y agoCan not recommend this enough. Prolog with great typing.
- alfiedotwtf 7y agoI find it reminds me a lot like Neo4j's Cypher, and I've been wondering how hard it would be to hook up Neo4j as a backend as Prolog's datastore
- basetop 7y agoIt is a declarative language like SQL. If you come from traditional imperative programming side, it is very difficult for you to get used to. I forgot who said it : "With imperative style, you code the precise steps to get what you want. With declarative style, you describe what you want and you let the language/runtime/OS/etc get it for you." If you're used to C/C++/Java, then SQL or Prolog seems frustrating, unnatural and non-intuitive. But once you have the eureka moment and realize they are declarative, you appreciate the elegance and power of SQL or Prolog.