18

From what I've seen of Prolog, it seems as if it would be ideal for crafting a rule engine for an app. Yet, I don't believe I've ever seen a rule engine written in Prolog. Is there some inherent limitation in Prolog (e. g. poor garbage collection algorithm) that would prevent it from being used to build a rule engine?

Onorio Catenacci
  • 2,937
  • 3
  • 26
  • 37
  • 7
    The ladder. (almost) no one knows prolog, and even more devs don't want to know anything that doesn't get their daily work done so they can go home. Unfortunate, Prolog's pretty cool. – Jimmy Hoffa Jul 16 '13 at 17:46
  • I've heard that Prolog is sometimes used in games, for AI. It might be used in games that need rules engines as well... – FrustratedWithFormsDesigner Jul 16 '13 at 17:49
  • 3
    Prolog makes a great edsl though. Embedding prolog in a language like Haskell or Scheme is the approach I usually take – daniel gratzer Jul 16 '13 at 18:00
  • 3
    @JimmyHoffa That's diminishing. Some peoople learn prolog and then try to proactively forget it for the rest of their working life. – ZJR Jul 16 '13 at 18:05
  • 5
    I see 3 close votes--anyone care to tell me what's wrong with the question so I might fix it or withdraw it? – Onorio Catenacci Jul 16 '13 at 18:21
  • 2
    I voted to close as "primarily opinion-based." If you can convince me otherwise, I'll retract my close vote. I personally found Prolog to be opaque; I would expect a rules engine to have a more intuitive syntax for defining rules. And it *is* a programming language, not a syntax prototype for a rules engine per se. – Robert Harvey Jul 16 '13 at 18:29
  • @RobertHarvey I can see your point; I've reworded the question. – Onorio Catenacci Jul 16 '13 at 21:12
  • 2
    I retracted my close vote. (pretty cool new tool). – Robert Harvey Jul 16 '13 at 21:17
  • Take a look at http://stackoverflow.com/questions/1817010/embedded-prolog-interpreter-compiler-for-java — maybe Prolog is not as unpopular. – 9000 Jul 16 '13 at 21:23
  • 2
    @OnorioCatenacci There could be an infinite number of reasons therefore an infinite number of answers. I didn't vote to close, but I can see why people did. – Dynamic Jul 16 '13 at 21:25
  • 1
    @Dynamic: there could be compelling reasons, like patent encumbrance (see video codecs), or inherently poor performance (see bubble sort), or a clearly superior technological successor (see BCPL vs C). – 9000 Jul 16 '13 at 21:30
  • What are you using for the definition of rule engine. If you expand to include term rewriting, then you get into a lot more applications, and if you take the REPL off Prolog to leave unification + back chaining, then you can get into lots of other things including type inferencing in functional languages. So where are you drawing the line with your definition of rule engine. – Guy Coder Jul 16 '13 at 22:10
  • @Dynamic I tried rewording the question so it's not quite so open-ended. – Onorio Catenacci Jul 17 '13 at 00:51
  • 1
    This is still open ended, and relying upon opinion. And it's not demonstrating that much prior research. I think the question is interesting and can reflect a change in what languages were used for rule engines. But I can't see how a single answer can be selected at this point as the best answer to your question. –  Jul 19 '13 at 13:17

3 Answers3

16

Rules engines in their infancy were written almost exclusively in Prolog--it was the logical language. For a small set of rules they worked great. However, it turned out they didn't scale very well. I don't have a definitive reference, but my understanding is that the way Prolog handles the chaining of rules is inefficient--the recursive model made for creating very large stacks that brought it to a crawl.

The development of the RETE algorithm and its successors allowed for a more efficient way to process large quantities of rules, and so took over.

Perhaps modern prolog would be more efficient than back in the 80's, when most of the early work was done.

Matthew Flynn
  • 13,345
  • 2
  • 38
  • 57
  • See also: http://stackoverflow.com/questions/3364191/forward-chaining-vs-backward-chaining/3364391#3364391 – Matthew Flynn Jul 20 '13 at 03:15
  • 1
    Another article dealing with this: http://haleyai.com/wordpress/2013/06/22/confessions-of-a-production-rule-vendor-part-1/ – Matthew Flynn Apr 09 '15 at 16:34
  • Crazy question. Didn't people implement RETE in prolog, thereby getting the best of both words? (there's a lot that RETE doesn't do that prolog does). – user48956 Jun 14 '19 at 18:36
14

Tongue-in-cheek answer: because if the creators of Rules Engines knew about Prolog (or Mercury or PLANNER or …) they wouldn't be writing Rules Engines, they'd be using Prolog.

Jörg W Mittag
  • 101,921
  • 24
  • 218
  • 318
5

Generally, the point of a rules engine is that it is a part of another application. It is rather rare to see applications written in Prolog, and there isn't a commonly available interface to connect Prolog to applications written in other languages.

One rule-based tool for rule engines, that is written to be added to other applications, is CLIPS. CLIPS was based on OPS5 and uses the Rete algorithm for pruning rules.

Tangurena
  • 13,294
  • 4
  • 37
  • 65
  • not entirely true, there are some interfaces from external programs to Prolog code. SWI-Prolog has a C++ interface and a way to connect to R. –  Jul 16 '13 at 22:20
  • 3
    Actually all prolog engines I've seen work with C or C++ as "nobody" uses Proolog for complete apps, but "everybody" ahs ways to call C functions to call specialized libs. i.e. GNU Prolog http://gprolog.univ-paris1.fr/manual/html_node/gprolog065.html – johannes Jul 16 '13 at 22:58
  • Thanks for that pointer @johannes. I was unaware of GNU Prolog at all; much less the fact that it can be called from C. – Onorio Catenacci Jul 17 '13 at 00:50
  • Also see: http://www.swi-prolog.org – user48956 Jun 14 '19 at 18:37