Hacker News new | ask | show | jobs
by ronnieCA 5678 days ago
While logical programming is powerful, it is only useful in certain situations. Due to the way Prolog backtracks to find a final solution, it can be increadibly slow, and it has to be able to 'undo' an operation.

While it is a much different language now, Erlang was originally based on Prolog, and has been adopted, modified and extended to be a much better "realworld" language.

2 comments

It's not that Prolog necessarily backtracks to find the final solution. It's the forward computation that actually builds the solution, backtracking only when one can't be found with assumptions made so far.

Sloppy programming can lead to lots of unnecessary backtracking, of course, but some of the main benefits of Prolog come in using it for problems where you would have otherwise written your own ad-hoc backtracking search process to find a solution. That is, good Prolog code only likely to be slow because of it's backtracking when an imperative solution would have been slower/buggier.

Runtime slowness because Prolog is a dynamically-typed language that also strongly encourages the development of meta-intepreters as a common tactic is a separate issue. Often times a slower run time is acceptable in exchange for a much faster development time with the use of custom metalanguages (DSLs).

Integrated search aside, another benefit of logic programming comes in declarative knowledge representation. In an expression optimizer I wrote, it was easy to concisely define several code substitution patterns as simple logical statements and then create the overall optimizer as an interpreter over those declared patterns.

For problems that don't really revolve around search or knowledge representation (i.e. most CRUD web stuff), Prolog doesn't provide practical benefits. Nonetheless, understanding the otherwise foreign concepts of the language can give you the seeds of new design patterns and idioms for your familiar languages.

Due to the way Prolog backtracks to find a final solution, it can be increadibly slow, and it has to be able to 'undo' an operation.

On top of that, from what I recall, it's pretty easy to have the backtracking to stumble into an infinite loop. As leaky abstractions go, that's pretty severe, probably enough to make people question the abstraction's usefulness.