5 ms·
In modern Prolog systems, this is in fact done: When looking up clauses from the database, the Prolog system builds an index as needed based on which arguments
by triska 4y ago
In modern Prolog systems, this is in fact done: When looking up clauses from the database, the Prolog system builds an index as needed based on which arguments of the query are instantiated. This is called Just-In-Time (JIT) indexing.
Modern Prolog systems also perform multi-argument and deep indexing. In older Prolog systems, you sometimes had to declare explicitly on which arguments the system should index, analogous to those database systems where you have to declare indices manually.
- ginko 4y agoIt sometimes feel like me learning Prolog completely ruined me for SQL. Doing even simple things seems ridiculously hard with SQL.
- triska 4y agoIn his seminal paper A Relational Model of Data for Large Shared Data Banks, Codd explicitly mentions first-order predicate calculus as a suitable formalism for the sub-language. Quoting from https://dl.acm.org/doi/pdf/10.1145/362384.362685 https://dl.acm.org/doi/pdf/10.1145/362384.362685: "The adoption of a relational model of data, as described above, permits the development of a universal data sub-language based on an applied predicate calculus. A first-order predicate calculus suffices if the collection of relationships is in normal form." One great advantage of using Prolog is that queries themselves are so readily amenable to analysis and reasoning with the same mechanism, and it becomes very easy to optimize them by reordering goals.
- kristiandupont 4y agoYou just piqued my interest in Prolog more than any pitch I had heard until now. Would you care to elaborate? How is it nicer than SQL?
- vkazanov 4y agoUnlike SQL, Prolog's core language is both simple and composable: about 200 pages. Sql is just a bunch of special cases and unfortunate historical accidents. It's a lot like... Php4 in comparison with StandardML. And, sadly, both SML and Prolog are fading away, while SQL (and php) are here to stay.
- jjtheblunt 4y agoDoesn't SML live on in Ocaml and F# ?
- vkazanov 4y agoThese are parallel branches of the same language family, along with Haskell. They are relatively popular but I can't say they flourish. Besides, SML always was the cleanest and most consistent of the bunch. Which kind of supports my point: it's not always the best language that wins.
- thesz 4y agoFor me it is the other way around. Prolog allows effects on its database while executing the "query" - you can add or remove facts from database. SQL prohibits that, separating queries and data manipulation statements. And, of course there are things like list comprehension in Haskell and other languages which are more or less the same as SQL but definitely more succinct.
- gota 4y agoHm, the language does not enforce it, but you _can_ separate things neatly for sure I may have missed something, though, are you thinking of something other than asserting and retracting?
- wizofaus 4y agoCan you syntactically write a SELECT query that also does an UPDATE/INSERT/DELETE? And Bobby Tables doesn't count - using a ; clearly indicates the start of a new query/ statement.
- triska 4y agoAs I see it, the fact that this (legitimate!) question even arises is saying a lot about SQL syntax: Can we syntactically write a SELECT query that also does an UPDATE/INSERT/DELETE? It may be possible, or it may be not possible, and to find out which it is, one has to have a good grasp of a quite complex syntax specification. For comparison, in Prolog, queries have a very uniform and simple syntax, and a small set of predicates is used to modify the database. You can find out whether a query performs any of these operations by meta-interpreting the query. It is easy to write a meta-interpreter for Prolog queries, and to allow only calls of predicates that you know do not affect the database. In comparison, it is extremely hard to analyze and interpret SQL queries, also because the syntax of SQL is so complex that we cannot easily answer such basic questions about the syntax.
- thesz 4y agoThe meta-interpretation will not say anything more than "this query may modify facts' database". Anything above that requires actual interpretation with rollback of changes. Because, you know, of halting theorem. Last time I checked, rollback of changes made into facts database was not even a notion in Prolog language. There was no notion of transaction in Prolog. "meta-interpretation" of SQL statement amounts to looking at the statement type, whether it is an INSERT/DELETE/UPDATE or just a SELECT query. There is no much complexity in the SQL syntax. My first experience writing more or less non-toy parser was to parse SQL schema, it was 20 years ago. SQL is not harder than VHDL with its context-sensitive lexing phase, where you can't answer is '(' a character literal or is it a part record type value construction. Maybe, DELIMITER can bite you, but, again, it is not hard to parse with parsing combinators.
- Yoric 4y agoI've only ever seen/used Prolog with a fixed set of facts (axioms? I forgot how they are called). Are there modern Prolog systems with on-disk storage that could replace a DBMS?