Great to see ongoing interest in Prolog. I did my Master's thesis in Prolog back in the "Fifth Generation" days [1] ... obviously the hype was waaaaay overstated but it still significantly influenced my thinking. I really think of it as one of those languages like Lisp or ML that opens your mind even if you don't wind up using it in your day-to-day job.
Plus, I thought it was entertaining to see this on the front page at the same time as "Hello, declarative world" :)
And I did mine more recently (2010) [1] :) (Mostly semantic web stuff ... showing how it can far outperform Java based SPARQL implementations for some stuff).
It was a real joy to work with semantic web data in SWI-prolog! Prolog lets you raise your level of abstraction so quickly, as defining prolog rules basically is a form of creating "named queries", something that is not possible e.g. in SPARQL (the canonical semweb query language).
I can't understand why this feature of prolog is not implemented more widely in more recent systems. The only example I know of that does, is Datomic [2], by Rich Hickey.
We're a pretty heavy user of Prolog for several systems. We use it for doing end of day allocations to prime brokers to determine the optimum allocations, basically a constraint solver.
I had it in the trading system for some time but I had to pull it out as I couldn't find a way to make its runtime deterministic enough. Most of the time it would be great and then on occasion I'd get 100 millisecond pauses:( I could never figure out if it was me doing something, the C bindings we were using or if Prolog just has a mind of its own:)
If anyone has any pointers on how to reason about the run time efficiency and performance of your prolog code I'd be willing to buy you a coffee!
As a first guess, this sounds like garbage collection pauses. Details of what to do about them depend on the particular implementation.
In SWI you can use the profiler to see if the garbage collector is in fact being called when you don't expect it. Then: (a) change the default (veeery low) garbage collector settings to use more memory before collection is triggered; (b) make sure you're not leaving unnecessary choice points around (listed as "redo" by the profiler, fix with correctly placed green cuts); (c) call garbage_collect/0 yourself at well-defined points when you're currently not doing low-latency stuff; (d) possibly (but I have no personal experience with this) turn off the garbage collector completely for certain sections of the code.
change the default (veeery low) garbage collector settings to use more memory before collection is triggered
I'm not familiar with Prolog GC but in other systems, making GC less frequent just tends to cause each collection to take even longer, as more objects have been created between each pass.
That is true as a general trend, but in my experience with SWI-Prolog the effect is not linear, and frequent small collections do cost more (in MY applications). For one thing, if you have long-lived data used throughout the program's whole lifetime, they will be visited on every collection without ever being freed. For another thing, if you have enough memory to fit all the data ever allocated by the program, you may not need to collect at all! Also, as mentioned in my previous comment, depending on the application there may be program parts where it is OK to trigger even a long-ish collection manually, while you want other parts to be fast and collection-free.
So, to reiterate: You are right in broad terms, but it all depends very much on the details of the application.
Depending on how you are using it, you could look into an actual constraint solver like Gecode or a more deterministic logic language like Dyna. The latter would probably require some implementation work - the only production-quality implementations I know of are proprietary.
If anybody is interested in Prolog, you might find this old blog post of mine useful. I cataloged a number of pretty useful online (freely available, legal) Prolog learning resources:
Sadly I've only just now finally gotten around to investing some time in to trying to learn Prolog myself. I got as far as creating myself a Github repo[1] and writing "Hello, World" and figuring out how to run Prolog programs at least. It's not much, but ya gotta start somewhere.
I'm glad to know I'm not the only person who creates "learning_xyz" repositories that may or may not progress very far, though I've yet to share any of mine online.
I only recently started sharing mine. I decided there was no real reason not to, and possibly some advantages in doing so. For one, it lets anyone looking at my GitHub profile know what kinds of things I'm into, beyond my "primary" projects. And it opens up the possibility of collaborating with friends and acquaintances (or, as far as that goes, total strangers) on some interesting stuff. I also find it motivational, especially when I work on increasing length of my "streak" of activity on GitHub.
Yeah, but that kinda defeats the point. What I've been trying to do is focus on making at least one commit a day that at least fixes something trivial, like replacing a "println" statement with a "log.debug" or "log.info" or whatever (in some Grails code). This way I'm both slowly and steadily improving the code, and I get to push my streak.
I had a Prolog class in university and also fiddled with it a bit extracurricularry. My biggest gripe was that (aside from being untyped and having poor support for higher-order programming, but that's probably remedied in more modern logic programming languages such as Mercury) for more complex use cases and computations the system degrades into functional programming with poor syntax: logical relations become deterministic functions with designated inputs and output, at which point I would be just better off with FP + backtracking (for example, the list monad in Haskell).
I like how posts about Prolog get populular very fast, but have little to no comments. People have heard that this language is special but have never actually used it in production, so they hope that someone will shed the light on it. Unfortunatelly it usually ends with a copypasted list of 15 projects(including Watson) where Prolog is used and thats it.
Maybe someone can share his/her production level experience with it this time...
I've never actually used Prolog, but like you say, it always seems like a really cool language. That said, I always wondered why it needs to be a language instead of just a library in another language. It seems there are some types of problems that are really well suited to Prolog, but I don't think it necessarily applies to all problems. So why not use another language and then bring in the relational piece as a library? Granted, I think that's what Kanren does in Scheme, but it doesn't really seem to be all that common.
Also, maybe I misunderstand, but doesn't using Prolog limit you to the unification algorithm used? If you wanted to build something like the Cassowary constraint solver in Prolog would it be really easy or would you still need to implement the algorithm from scratch?
That's exactly how I use Prolog - embedded in the other languages. It is especially invaluable inside compilers (alongside with an optimised Datalog). And I had to extend the default unification for implementing some exotic type systems.
> Maybe someone can share his/her production level experience with it this time...
What do you want to know? I have written a few thousand lines each of production-quality Prolog in two distinct projects. It works well if you know what you're doing, the problem domain is a good match, and you don't need to rely on bindings to loads of external libraries. If you don't know what you're doing, it's easy to write slow and buggy code.
If you want to play with prolog it is actually quite easy to implement. Languages like Shen have a fully functional prolog in the language. Maybe not with all the fun bells and whistles of bigger languages, but still enough to play around with.
IBM Watson uses Prolog? That is interesting. I have been helping a friend for a year integrate IBM Watson into his product, but I don't know much about how Watson is implemented.
Yep. Watson has been described as "mostly written in Java, with some chunks in C++ and some in Prolog"[1]. The Prolog is apparently mainly used for language parsing[2].
Also the open source UIMA[3] project is heavily used by Watson. UIMA started out as an IBM project called OmniFind (IIRC) and was later donated to the ASF.
Some background on why Prolog for parsing: That was traditionally a popular use of Prolog, because something similar to BNF-style grammar rules can be written almost literally as Prolog clauses, and you get a parser for "free". Very easy to prototype, plus since it's just Prolog clauses that can be used by the rest of the Prolog program and vice versa (not black-box tables generated by YACC), you can muck with edge cases, integrate error reporting, call out to information-extraction heuristics where relevant, etc. The technique is "definite clause grammars" (DCGs), and can either be written directly in normal Prolog, or with some syntactic sugar that most Prolog implementations include. Here's a tutorial: http://www.pathwayslms.com/swipltuts/dcg/
Compared to when DCG parsing was most popular ('70s-'90s), there are now more alternatives for easily working with grammars, though, including non-black-box approaches nicely integrated into languages, like combinator parsers in Haskell and LPeg in Lua. So it's not quite as unique today, though it's still a nice way to prototype parsers.
A suggestion to anyone who's interested in logic languages, like prolog: Give The Reasoned Schemer by Daniel P. Friedman a try. It's an easy, fun book, with surprising depth if you give it some effort and thought. .
When I used Prolog at university, we built really cool constraint solvers using hardcoded predicates, but is it possible to create the predicates dynamically? To be useful, if a user has a GUI where they can define rules, they've got to be loaded into the program somehow... hopefully not through code generation?
I think one of Swi-Prolog's great advantages is the large library, especially tools for the semantic web. I have not had any consulting work using Prolog in at least 8 years and don't do much for-fun Prolog programming either. I used to find Prolog especially good for hacking together quick prototypes.
I am OS guy . so I don't have so much experience in other than C.
Yesterday I was watching youtube video about prolog , and I amazed by Logic Programming concept.Maybe for most of you it is ordinary concept , but for it was wonderful and I have plan to continue it in my spare time.
Plus, I thought it was entertaining to see this on the front page at the same time as "Hello, declarative world" :)
[1] https://en.wikipedia.org/wiki/Fifth-generation_programming_l...
[2] https://news.ycombinator.com/item?id=10219780