> "<i>Don't be bothered with by the fact that the solutions end with "or false" here. It's a function of how the search algorithms work; the solver looked for more solutions, then failed. I'll admit, I don't totally understand why it only sometimes does this, but it's expected.</i>"<p>I think this is explained in The Power of Prolog[1] that the answers coming from Prolog are not printing text to a terminal, they are valid Prolog terms(/data/code). That's why the result uses the same `;` for OR as code does. Answer (x ; y ; false) is "query can be answered by x or y or no other answer found". (This would let you do meta-programming, reasoning about the results and rewriting the results in a LISPy data-as-code way, if you were more advanced than I am).<p>Prolog systems do optimisations to jump to the correct answer without searching, if they can, (e.g. database style indexing on the facts and rules) and in those cases there is no code left to search after showing the first answer, no need to prompt the user "should I search for more answers in the remaining code?", and so no need for an output "false" to say "I finished searching and found no more solutions".<p>[1] <a href="https://www.metalevel.at/prolog" rel="nofollow">https://www.metalevel.at/prolog</a>
This embodies why I don't like Prolog. Prolog's philosophy is that you should just write the predicates without thinking about how the engine works. But as soon as you do something actually complicated, you realize that the different optimization modes of the engine give different results, and shortly after that you'll find yourself in the "exhaustively try every possible combination until we get one that satisfies the predicates" mode, and your code will go from taking 1 second to run to taking 8 days.<p>And because you don't control the engine (you're not supposed to think about it, after all), there's nothing you can do but rewrite the whole thing in a traditional programming language.
> <i>as soon as you do something actually complicated, you realize that the different optimization modes of the engine give different results</i><p>The same is true of SQL query planners. You can perform basic queries without understanding how your SQL engine of choice works under the hood, but if you want performance, you must understand how your DB works. SQL is just the interface.<p>This is different in kind from imperative programming languages (which are much closer in abstraction to the underlying machine architecture), but we rub along with SQL ok; why not Prolog?
> Prolog's philosophy is that you should just write the predicates without thinking about how the engine works.<p>This is the definition of declarative programming[0].<p>0 - <a href="https://en.wikipedia.org/wiki/Declarative_programming" rel="nofollow">https://en.wikipedia.org/wiki/Declarative_programming</a>
I somewhat disagree that you shouldn't be aware of how the engine works. The mechanics are quite simple. Prolog's horn clauses are combined in depth first search manner trying to proof that the negated goal is false.<p>However, most prolog books focus on rooting the declarative mindset because programmers are generally more familiar with imperative programming. But just as with SQL or lisp there are definitely good ways, bad ways and plain mistakes you can make when approaching a problem.
How is this different from other programming languages though?<p>One example I often think about is from Ken Silverman: "sub eax, 128" → "add eax, -128". So equivalent ways to write the same program may have different performance characteristics also depending on the tools that are applied. How many people could tell without trying which way to write this example is preferable?<p>The same phenomenon will be encountered in all kinds of languages, where engine and compiler improvements make existing code faster or slower.
Very nice!<p>In the Scryer Prolog discussions, Alex has shared a few ideas and considerations for possible improvements to the Prolog code, including the use of metaprogramming to automatically generate more general relations:<p><a href="https://github.com/mthom/scryer-prolog/discussions/3221" rel="nofollow">https://github.com/mthom/scryer-prolog/discussions/3221</a><p>I hope for an interesting followup article!<p>Another very interesting Prolog program by Alex is factgraph.pl:<p><a href="https://github.com/alexpetros/factgraph.pl" rel="nofollow">https://github.com/alexpetros/factgraph.pl</a><p>It's a Prolog implementation of the IRS Fact Graph, an application of <i>Law as Code</i>.
It continues to be immensely surprising to me that Joe Armstrong was able to write the initial Erlang implementation in Prolog. I wish I’d asked him about getting a copy of the source code.
<p><pre><code> What does this say about Forth? Not much except that it isn't for me.
Take Prolog. I know few things more insulting than having to code in
Prolog. Whereas Armstrong developed Erlang in Prolog and liked it much
better than reimplementing Erlang in C for speed. I can't imagine how
this could be, but this is how it was. People are different.
</code></pre>
from Yossi Kreinin's "My history with Forth & stack machines" [0]. Some people write APL and enjoy it. Some can't bear Lisp even after 10 years of working with it.<p>[0] <a href="https://yosefk.com/blog/my-history-with-forth-stack-machines.html" rel="nofollow">https://yosefk.com/blog/my-history-with-forth-stack-machines...</a>
Regarding distributed systems, I find Torbjörn Lager's recent work on <i>Web Prolog</i> particularly interesting. He recently posted about it here:<p><a href="https://github.com/mthom/scryer-prolog/discussions/3322" rel="nofollow">https://github.com/mthom/scryer-prolog/discussions/3322</a><p>and also in the course of a discussion on various approaches to implement <i>concurrency</i> in Prolog:<p><a href="https://github.com/mthom/scryer-prolog/discussions/3307" rel="nofollow">https://github.com/mthom/scryer-prolog/discussions/3307</a>
When i was in uni, the course teaching Prolog and Lisp was called "Artificial Intelligence for Engineers".
Was initially nonplussed, but toward the end I realized the choice of pokemon for an example actually works out well for showing how prologue can solve problems. I’m now a bit curious about trying it out somewhere.
Prolog is actually a perfect fit for all kinds of adventure, role playing, strategy, and classic board/card games, with clauses representing game rules and facts representing the game state and universe in the most natural way.<p>Simple general-purpose opponents can be coded using just recursive backtracking search, while more advanced ones (supporting moves that need to destructively change state) can still be conveniently modelled by reifying facts and thereby enable backtracking over assert/retract-like Prolog DB modifications, as used in discrete combinatorial planners [1].<p>[1]: <a href="https://quantumprolog.sgml.net/container-planning-demo/part1.html#finding-loading-plans-with-multiple-stops" rel="nofollow">https://quantumprolog.sgml.net/container-planning-demo/part1...</a>
All examples shown in the article can be ran with Datalog too (with stratified negation and arithmetic comparison), which has a clearer execution model and looks almost identical to Prolog. Prolog underneath is doing backtracking, while Datalog is finding a least fixed point of derived relations where iterating on data won't produce more relations, and is akind to SQL (but usually stronger because of recursion).
Nonplussed like initially surprised? It does not mean bored or nonchalant which many people seem to think, probably due to the non- prefix.
Interesting, it seems I learned/am using a modern American mutated version of the word.<p><a href="https://www.broadlearners.com/t/understanding-the-meaning-of-nonplussed-and-its-confusion/3418" rel="nofollow">https://www.broadlearners.com/t/understanding-the-meaning-of...</a><p><a href="https://www.merriam-webster.com/grammar/whole-nother" rel="nofollow">https://www.merriam-webster.com/grammar/whole-nother</a><p><a href="https://old.reddit.com/r/etymology/comments/13s19j0/wtf_happened_to_plussednonplussed/jlnk4iw/?context=10000" rel="nofollow">https://old.reddit.com/r/etymology/comments/13s19j0/wtf_happ...</a><p>In my case, I was using it as almost a blend of the two meanings, something mostly meaning “unimpressed”, with a touch of “and a bit perplexed why such effort is going into this”. Basically a shoulder shrug and “okay…?”<p>I now find myself <i>nonplussed</i>, wondering if I should be using the word at all given it seems to have two opposite meanings.
If this is your article, you have a typo in learns_priority/3, "move_priority #> 0" should be "P #> 0".
Are there public tournaments of games like Pokemon where contestants have to compete with eachother using a specific class of algorithms (e.g., logic programming, neural nets, linear programming, etc.)?
> Then query it like so:<p><pre><code> SELECT DISTINCT pokemon, special_attack
FROM pokemon as p
WHERE
p.special_attack > 120
AND EXISTS (
SELECT 1
FROM pokemon_moves as pm
WHERE p.pokemon_name = pm.pokemon_name AND move = 'freezedry'
)
AND EXISTS (
SELECT 1
FROM pokemon_types as pt
WHERE p.pokemon_name = pt.pokemon_name AND type = 'ice'
);
</code></pre>
Hmm. I wonder if this<p><pre><code> SELECT DISTINCT pokemon, special_attack
FROM pokemon as p
NATURAL JOIN pokemon_moves as pm
NATURAL JOIN pokemon_types as pt
WHERE
p.special_attack > 120 AND
pm.move = 'freezedry' AND
pt.type = 'ice'
;
</code></pre>
would work instead.
It would, but it forces the requirement of DISTINCT. With the original, if there were declared PKs (pokemon_name is fine for the main table, with a composite for others), the semi-join (EXISTS) would eliminate the need for DISTINCT entirely.<p>I think. Doing this in my head, but you could verify it trivially with SQLite or any other RDBMS.
I'm not familiar with Pokemon universe :(
Can somebody please explain Pokemon using Prolog?
Love this use case, makes me want to implement something similar for Magic the Gathering. I love using scryfall, but I think a more cli first approach with descriptive rules would suffice much better for brewing in eternal formats like Commander with ever growing card pools. I mostly work off of keyword search.
Are there pokémon with backtracking and unification traits? Those could do real Prolog!
That's very helpful & easy to follow.<p>Do you have an Odin tutorial that's as easy to digest?<p>Sol