Live data from Hacker News

The Power of Prolog

metalevel.at

111–120 of 162 posts

Re: The Power of Prolog

#111
post #61

Earlier quoted context omitted.

In my experience, the trick is to let go of the imperative reading since it becomes too complex in the situations you mention. Instead, focus on declarative properties: Does your predicate (or DCG) succeed in cases it shouldn't ? Then your program is too general , and you need to add constraints . Or does your predicate fail in cases it should succeed ? In that case, at least one of the goals is too specific . You ca…

>> Instead, focus on declarative properties: Does your predicate (or DCG) succeed in cases it shouldn't? Then your program is too general, and you need to add constraints. Or does your predicate fail in cases it should succeed? In that case, at least one of the goals is too specific. You can use declarative debugging to find out which goals are responsible for the failure. That's good advice and I realise it articula…

The thing is findall/3 is not really in the standard pure part of Prolog. It has the form: findall(Template,Enumerator,Instances), and can be read as: `Instances is the sequence of instances of Template which correspond to proofs of Enumerator in the order which they are found by the Prolog system" (Craft of prolog) This reading is meta logical because it depends on the instantiation of variables in Template and Enumerator and on the proof strategy of the Prolog system. So for example if you used a meta interpreter to change the search strategy of Prolog from topdown to bottom up, then the result of a call to findall would change. setof/3 does not have this problem because it finds the ordered set and can fail (in contrast to findall which will return an empty list) You need to bear in mind we as programmers are concerned with answers to a query but Prolog returns proofs... I now try and avoid findall/3 in my programs and only use it when I am doing input and output from my core program.

Re: The Power of Prolog

#112
post #89
post #88

Earlier quoted context omitted.

Well, I need to keep both pipes open during the "session", since usual radare2 session involves hundreds of commands and their output. Opening a new pipe and process every time is a wrong way to go in my opinion.

You should be able to open the pipes at the beginning of the session, and close them after, passing the pipe variables around as needed. Prolog wouldn't be any different to other programming languages there. What errors are you getting? Maybe post to the swipl mailing list?

I will send a message to mailing list then, thanks for the suggestion.

Re: The Power of Prolog

#113
post #101
post #47

One of the coolest things I've seen is to use Prolog with CLP(FD) to solve the 7-11 problem. The problem basically says the sum of the prices of four items is $7.11, and the product is $7.11 too (no rounding); find the prices of these four items. This can be solved in two lines of code that gives the (unique) solution in a second. Not even my expensive Mathematica can do this! ?- use_module(library(clpfd)). true. ?-…

But, but, the product of four prices cannot possible be measured in $. You must mean $^4. Edit: Here's a solution in Haskell. I've been paid to program in both Prolog and Haskell, but it was a while ago; my knowledge of both languages is very rusty. main = putStrLn $ show [(a, b, c, d) | a

Amazingly, this gives an answer within not too many tens of seconds of full CPU usage. (I interrupted it before it finished searching the full space, though.)

Re: The Power of Prolog

#114
post #28

Earlier quoted context omitted.

Actually, I think we are both right. http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Web...

That link just shows a proposed third party IRQ config system for DOS, but wasn't actually shipped in Windows (in addition to the NT networking config).

Unbelievable. Often wondered how a prolog friendly os would feel..

Re: The Power of Prolog

#115
Prolog: just say no.

(To explain the joke, one of the main problems with Prolog is that solutions which cannot be unified just emit a "no" with no further explanation, making large Prolog setups hard to debug)

Re: The Power of Prolog

#116
post #12
post #9

One of my favorite languages, pity that is has had even harder time than Lisp getting mainstream acceptance.

Let's face it, procedural is just plain easier to debug because you can more easily split it into digestible and dissect-able chunks: divide-and-conquer. Perhaps functional and logical CAN readily have such features, but nobody either figured how, or have not figured out how to explain how to do dissection to normal people. (This is sometimes a criticism of SQL also, but the added WITH clause helps break up big queri…

This is backwards. Debugging is much easier in a functional language because you already have your program division done for you, and immutability makes it much easier to understand what's going on since you can compare function inputs and outputs really easily, and e.g. if you ever accidentally step past the part you were interested in it's always safe to "drop frame" and step forward again, with the same behaviour, whereas if your program is mutating state then that state mutation has now happened and you can't ever debug it without restarting the whole thing.

Re: The Power of Prolog

#117
post #19

Earlier quoted context omitted.

Thank you for sharing this, I really appreciate you participating in this thread and this awesome anecdote! One related workplace anecdote that a former fellow student told me: He was working on a rule-based medical recommender system, and he recognized that Prolog was an excellent fit for this project. When he first suggested that the team switch to Prolog, they were very skeptical. But someone high up in the chain…

> My colleague told me that, a few months after that, the whole team regarded Prolog as the only viable solution to all further projects from then on! Hm, there is such a thing as the right tool for the job. If all their jobs were very similar that makes sense, otherwise, not so much. Are you aware of the fact that inside every Windows NT installation there was a Prolog engine to help with network configuration? http…

[deleted]

Re: The Power of Prolog

#118
post #41

Earlier quoted context omitted.

Sure, if you do not have the debugger you use the logging, but you will miss the main features of a debugger like see the entire call stack, all the variables and parameters at each call stack level, you can evaluate expressions in that context. I use logging to log problems that would happen on a user machine or server where I can't open the debugger and see it. When an error happens on a server or a customer machin…

Each do better under certain situations. One is a hammer and another a tweezer. Different debugging jobs/steps need different tools. But the real question is whether the hammer/tweezer kit that comes with Prolog is better than the hammer/tweezer kit of other paradigms/languages. In my personal opinion and observation, the hierarchical step-wise refinement approach is quicker for most developers to grasp, learn, and d…

Prolog is ideal for some kind of problems, good programmers should know what logic programming is and what problems are perfect for logic programming, then if in real life you hit such a problem you can chose prolog or a library that does logic programming.

Re: The Power of Prolog

#119
post #99

Earlier quoted context omitted.

Ooo! Lemme show off this CLP(FD) solution to the "Zebra Puzzle" https://en.wikipedia.org/wiki/Zebra_Puzzle that I made after reading the "Logic Puzzles with Prolog" chapter: https://gist.github.com/calroc/603ed919bc814ccee10c1b3df6142...

That makes Prolog look downright useful! I heard from lots of people that it's fun as an esoteric language and some had a homework assignment or two in it, but nobody really uses it in practice. Do you think this might be more useful as a module to solve logic puzzles, rather than as a complete language by itself? I learned the very basics, but not worked with it enough myself to say whether that would be better than…

Yes, a modern Prolog with CLP(FD) is very well suited to solve logic puzzles. There are many examples on the web, but you can look at this book on ECLiPSe CLP (nothing to do with the IDE, it's a Prolog system with good constraints support): http://www.anclp.pl/

However, nowadays I'd start with Minizinc and its default solver gecode: http://www.minizinc.org/ For combinatorial puzzles it's even easier than Prolog and very efficient. Just read the short tutorial and you should be good to go solving the Zebra/Einstein problem or similar: http://www.minizinc.org/downloads/doc-latest/minizinc-tute.p... Minizinc is purely declarative. When more control is needed then you can use Prolog.

Re: The Power of Prolog

#120
post #113
post #101

Earlier quoted context omitted.

But, but, the product of four prices cannot possible be measured in $. You must mean $^4. Edit: Here's a solution in Haskell. I've been paid to program in both Prolog and Haskell, but it was a while ago; my knowledge of both languages is very rusty. main = putStrLn $ show [(a, b, c, d) | a

Amazingly, this gives an answer within not too many tens of seconds of full CPU usage. (I interrupted it before it finished searching the full space, though.)

[deleted]
Post reply on HN