5 ms·
As an abstraction, think of a Prolog program as a collection of facts and running a Prolog program as a query against those facts. Or basically a Prolog program
by brudgers 8y ago
As an abstraction, think of a Prolog program as a collection of facts and running a Prolog program as a query against those facts. Or basically a Prolog program as a static (or read oriented) database. Or describing a set of rules.
Rolling back, as a declarative language in the database abstraction, the programmer can run queries with verbs that model the domain instead of SQL's generic WHERE, FROM, SELECT, etc. The price is that all facts have only three parts...like RDF [1] so maybe the programmer comes out ahead on design of the data relations.
Not all workloads are close to read-only databases. But some are, and Prolog allows writing such programs without the low level abstractions of the relational model using higher level DSL's.
[1]: https://en.wikipedia.org/wiki/Resource_Description_Framework https://en.wikipedia.org/wiki/Resource_Description_Framework
- YeGoblynQueenne 8y ago>> The price is that all facts have only three parts...like RDF [1] Prolog "facts" can have any number of arguments. The only way I can think of reconciling Prolog facts with your comment about "only three parts ... like RDF" is that Prolog facts are first-order predicates which consist of a predicate symbol, a vector of arguments and a pair of enclosing parentheses. Is that what you meant?
- deleted 8y ago[deleted]
- qwerty456127 8y agoHow does storing facts in the source code instead of a database make any practical sense? I mean I can hardly imagine a real-life scenario where the number of facts is so small.
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- ben-schaaf 8y agoFacts are both data and "source code". It's a fact that a user with id=0 has name=Bob. It's also a fact that the sqrt(x^2)=x or the http response code when a resource isn't found is 404. Some of those belong in databases, some definitely don't.
- brudgers 8y agoThis isn't a real life example, but illustrates the sort of facts that are difficult to maintain in a BCNF relational database...and are still difficult to query in a non-BCNF relational database. Paper covers Rock Rock crushes Scissors Scissors cut Paper In Prolog we might encode that: wins(paper, rock). wins(rock, scissors). wins(scissors, paper). loses(X,Y) :- wins(Y,X) Relational databases are good for storing context-free facts. In table T, the interpretation of row R1 is independent of the contents of row R2. A practical real-life scenario for Prolog might be a "help wizard." The next step depends on what steps we have already tried (and not tried) and other kinds of state. The next step can be expressed as a Horn Clauses. X /\ Y /\ NOT Z -> Z NOT B /\ NOT W /\ X /\ Z /\ A /\ Q -> M etc. If the Prolog and the Horn Clauses look a bit like regular grammars, writing compilers is another area where Prolog has been applied historically. The first version of Erlang is an example, and some of Erang's design made more sense to me after learning a little bit of Prolog. But I am into learning mostly useless subjects.