Ask HN: What are some interesting examples of Prolog?
41–50 of 64 posts
Re: Ask HN: What are some interesting examples of Prolog?
#42[0] https://github.com/hbrouwer/dfs-tools [1] https://www.sciencedirect.com/science/article/pii/S089054012...
Re: Ask HN: What are some interesting examples of Prolog?
#43At work we modelled our role-based access control logic in prolog. Once you realise that your authorization is logic programming, you gain access to better tools, more formal ways to think about it, and a treasure trove of literature. :)
Re: Ask HN: What are some interesting examples of Prolog?
#44Re: Ask HN: What are some interesting examples of Prolog?
#45Make files are prolog programs in drag.
Re: Ask HN: What are some interesting examples of Prolog?
#46It's a pretty wild concept, and there are tons of cool examples of what Prolog can do. Some examples are:
- A solver for Suduko puzzles: https://rosettacode.org/wiki/Sudoku#Prolog
- A simple game where you guess a person's age: https://rosettacode.org/wiki/Guess_the_number#Prolog
- A family tree program: https://rosettacode.org/wiki/Family_tree#Prolog
Re: Ask HN: What are some interesting examples of Prolog?
#47At work we modelled our role-based access control logic in prolog. Once you realise that your authorization is logic programming, you gain access to better tools, more formal ways to think about it, and a treasure trove of literature. :)
I would love to read more about this.
Re: Ask HN: What are some interesting examples of Prolog?
#48Echoing what triska said, CLP(ℤ) and friends are some of the most under-appreciated aspects of prolog implementations.
I'm amazed that programmers still don't have access to CLP when trying to do scheduling and planning solutions.
As an example in practice, what if you want to know about a transaction in which a number of entities transitively had holdings in one of the beneficiaries of the transaction at that particular time. The date window is not known, and the date windows are important in the ownership chain as well as the transactions that are being undertaken.
With CLP(FD) you can ask for a window of time, and the solution will zoom in on an appropriate time window which exists for the entire chain and match the time of the transaction.
Now try to do this query in SQL. It's almost impossibly hard.
I can't wait until I have the time to implement constraint variables for TerminusDB, but at the minute we are still working on more prosaic features.
Aside from that there are very interesting program correctness and optimisation systems which are based on prolog (usually a datalog). For instance Soufflé: https://souffle-lang.github.io
Re: Ask HN: What are some interesting examples of Prolog?
#49Re: Ask HN: What are some interesting examples of Prolog?
#50Given that you have the following coins, 1¢ (i.e. 1 cent or $0.01), 5¢, 10¢, 25¢, 50¢, how many different ways are there to give change for a dollar? For example, one way would be to give 2x50c, another would be to give 100x1c. How many are there total?
In most languages this is not super easy to do unless you're very comfy with recursion.
In Prolog the solution is basically (pseudocode):
100 = a*50 + b*25 + c*10 + d*5 + e*1
and Prolog will just figure out all possible combinations for you.The challenge with Prolog as far as I understand is making things fast.