Hacker News new | past | comments | ask | show | jobs | submit login

I recently used prolog for a complicated binary reverse-engineering task: bit packing. Likewise prolog is perfect for compilation.

https://savannah.gnu.org/forum/forum.php?forum_id=9203

In fact it's a better prolog, picat, which also allows pretty straightforward statements, like loops, and has solver support.

http://picat-lang.org/




A big point of using Prolog for the commercial projects fitting its niche (1) is that it's based on an ISO standard, though, and implementations are (theoretically) interchangeable. To make Prolog programs actually portable across major Prolog implementations, there's been the Prolog Commons initiative for an extended standard predicate lib.

1) personally I think Prolog is much more broadly applicable in all kinds of apps rather than just type inference, policy languages, games; but with the recent rise of Datalog as actual query and inference language (and not just in academic database literature), it seems Prolog's time has finally come

[2]: http://www.prolog-commons.org/


I agree with the other commenter’s Wow! Picat also supports satisfiability apps like MiniZinc does. Thanks for posting that link!


Initially I choose MiniZinc, but then was turned off by its baroque syntax. Straight prolog syntax and picat syntax was much easier in the end.

writing prolog is mostly about writing in the most natural and readable syntax possible. using haskell-like types put me off.



What types of problems does one use constraint programming for? Large optimization problems require something like CPLEX usually.


Constraint logic programming is generally proposed as a more natural alternative for arithmetic, in Prolog, than Prolog's native arithmetic functions.

It's a biig discussion and I'm not the one to make the argument for CLP, but, for example, in straight-up Prolog arithmetic is implemented using the is/2 predicate, which looks a bit like this:

  A is 1 + 2.
Where A is the result of the addition of 1 and 2. In CLP on the other hand, particularly in the CLP library for reasoning over integers, CLP(FD), the addition above looks like this:

  X #= 1+2.
Note that here, "#=/2" ("equals") is a constraint, so the statement above is true, iff the expression on the left-hand side of the #= is equal to the right-hand side of it. Which lets you do things like this:

  ?- 3 #= Y+2.
  Y = 1.
Where trying to do the same thing with is/2 will give you an error (because Y is not sufficiently instantiated). And because of how constraint programming works, you can also do arithmetic with ranges, like so:

  ?- X #= A + B, A in 1..3, B in 4..6.
  X in 5..9,
  A+B#=X,
  A in 1..3,
  B in 4..6.
In fact, what comes out the other end of the query above (the bit after the query prompt, "?") is a set of new constraints, where the result of adding A in [1,3] and B in [4,6] is a number, X, in [5,9].

You can find more information in the CLP(FD) library documentation, here:

http://www.swi-prolog.org/man/clpfd.html

Or, if Markus Triska (the author of the library) is around, he can probably elucidate its use a bit better than I can :)


Wow, thanks for sharing!




Consider applying for YC's first-ever Fall batch! Applications are open till Aug 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: