Real World Programming in SWI-Prolog
The golden language at my current place of work is Python. But we have some pretty gnarly business logic in some places (decision tree of average height 10 and branching factor of maybe 3).<p>To better understand how all the pieces fit together, I took on the challenge of writing the decision tree out in SWI-Prolog over the weekend, since I figured it would be the most “expressive” way to capture the logic.<p>I’d taken a PL class in college, and used prolog for a couple weeks therein. But this was the first time I’d used it in years. The first 30 minutes were a struggle, as I tried to remember how predicates worked, and tried to translate my mental model into a series of iteratively applied predicates. But after a couple  hours of very satisfying top-down programming, I’d written pretty much the whole thing.<p>And it worked!<p>My grand theory is that we’d be able to get compliance, legal, and finance (main stakeholders of the program), to interface with some exposed subset of the predicates, to tweak to their hearts content.<p>This program could be the Golden source of truth that all implementations would have to live up to. Maybe, we could even hook in python programs to do I&#x2F;O (fetch inputs from the databases, write decisions to the database), and use this prolog program directly to drive decisions in a python program.<p>It’s all a fantasy at this point, but it’s a fun one. The idea’s lingered since that weekend, many months ago.<p>Has anybody pulled off anything similar? Replacing a complex component of a bigger program with a prolog core?