
Ask HN: Production Prolog in 2020? - timxor
Seeker of logic programmers!
======
pjmlp
Upcoming Rust lifetime analysis engine, Polonius.

[http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-a...](http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-
alias-based-formulation-of-the-borrow-checker/)

------
TheUndead96
I think Prolog and logic programming will have a second renaissance. I think
at the very least a general artificial intelligence would require a logical
inference engine similar to Prolog.

~~~
thom
Do any of the non-artificial intelligences walking around out there contain a
logical inference engine similar to Prolog?

~~~
felixyz
Yes. Logic wasn't conjured up from abstract ideas, but from a concerted effort
to distill the essence of what humans (regular, average people) find
reasonable and convincing. (To mention just one example, there is a reason one
of George Boole's major works is called "The Laws of Thought".)

Our strategies for understanding language also involve inference and
unification that is similar to logic programming. This is not to say the exact
semantics and evaluation strategy of Prolog is what humans carry around, but
_part_ of our cognitive apparatus clearly operates in a manner _similar_ to
logic, and by extension Prolog.

I discussed this topic with one of the inventors of Prolog recently:
[https://thesearch.space/episodes/1-the-poet-of-logic-
program...](https://thesearch.space/episodes/1-the-poet-of-logic-programming)

~~~
YeGoblynQueenne
Plotkin's thesis! You had an interview with _Kowalski_? Wow :)

~~~
felixyz
You're on my wish list for interviewees too :)

~~~
YeGoblynQueenne
Wot me? Haha! Wait another 20 years maybe! But thanks, that's so kind :D

------
jmnicolas
Our pay software at work needs a Prolog engine (SWI). I think it's exactly
where it shines : a complex logic with a lot of small rules that would be a
nightmare to implement and maintain with a if / else logic.

~~~
ianamartin
I implemented something similar to that at a payments company a while back,
but not with prolog because I couldn't get buy-in. I wrote a rules engine
expressed as SQL tables, and it was absolutely better than if-else or switch.
It let us delete thousands of lines of code and also slap on a UI so that the
people managing the payments rules could make changes themselves. Highly
recommend.

~~~
EmielMols
In my experience, "logic wants to be code, and not data". Ie it's a dangerous
(although sometimes necessary) step to move this into the data domain. Did you
encounter any difficulties with missing source control, being able to use
debugging tools, etc?

~~~
barrkel
Logic doesn't want anything.

Highly regular logic is better expressed in generalizations, and inferable
logic is better expressed in a compressed, normalized fashion rather than
repeated and duplicated.

The more irregular logic becomes, the more it fights generalization and needs
special cases. The ultimate special case is a programming language (and code
is data too!). The risk in expressing rules in the form of data is that to
handle all edge cases, you encode a custom programming language without all
the resources that supports programming languages, like editors, debuggers,
source control, developer mindshare, stack overflow, etc. But not all logic is
irregular enough to warrant it.

------
thanatropism
There was a minor hype cycle with SMT solvers in 2019.

For a while I was extremely fascinated by SAT as an encoding for hard problems
that somehow had heuristic fast solvers; particularly by SATPLAN, the blocks
world, etc.

But there's an useful contrast with Lisp, the other thing everyone within a
radius of HN would like to emerge as winner. Lisp is essentially a syntax
concept. It isn't particularly opinionated about problems -- on the opposite,
it's indefinitely extensible to accomodate nearly everything. So we have
Clojure and Hy (a Lisp that superficially imitates Clojure but compiles to the
Python AST) and people doing scikit-learn ML on Lisp.

Logic programming, on the other hand, wants problems to be formulated on _its_
terms. It needs the world itself to change to "win big". Of course logic
programming problems aren't going to disappear, as sparse linear algebra
programs won't. But this isn't a paradigm, it's an application.

~~~
felixyz
Prolog-style logic programming is very different from SAT, SMT and Answer Set
Programming in this regard. Prolog has the same features that you describe in
Lisp. It's homoiconic, infinitely malleable, meta-level programming is
trivial, etc. I recommend having a look at:

[https://www.metalevel.at/acomip/](https://www.metalevel.at/acomip/) (A Couple
of Meta-interpreters in Prolog)

and

[https://github.com/triska/lisprolog](https://github.com/triska/lisprolog)

~~~
thelazydogsback
Understanding the declarative vs. operational semantics of Prolog (and how
things like tabling can bridge the gap in some cases) is one of the most
important concepts to master. It's really a shame that that more Prologs don't
support alternate operational models -- though it's pretty trivial to write
meta-interpreters with your own semantics (such as breadth-first eval, etc.)
it would be nice if there were canonical versions. For CLP & attributed-
variables at least there is some universality.

------
PedroCandeias
TerminusDB is a new project being implemented in Prolog:
[https://github.com/terminusdb/terminusdb-
server](https://github.com/terminusdb/terminusdb-server)

------
tluyben2
I really like working with
[https://mercurylang.org/](https://mercurylang.org/) ; I think there are a few
companies that use it for production software.

~~~
thelazydogsback
Seems like it had some traction like 10 years ago. I like the idea of
controlling backtracking, but then when I tried it I thought it got a bit
verbose w/all the mode decls. I should take a look and see if there's been any
changes recently.

------
CyberFonic
I did some work with SWI-Prolog. It is useful when the problem can be
effectively translated into Prolog's preferred form of terms and rules. But
the solver mechanism only solves a subset of logical inference needs. Prolog's
use of logic in AI should not be conflated with the AI/ML systems which use
networks of floating point operations, i.e. not boolean operations.

As always, best to choose the tool / language that best suits the problem.

------
ghufran_syed
Datomic uses Datalog, a dialect of prolog, that's what I would look at first
if I needed prolog in production in 2020.

------
q3k
Gerrit (code review) uses Prolog for submission rules. I guess that counts as
production prolog.

[https://gerrit-
review.googlesource.com/Documentation/prolog-...](https://gerrit-
review.googlesource.com/Documentation/prolog-cookbook.html)

------
badtuple
Kind of offtopic, but does anyone know a good resource around implementing a
simple prolog/similar language? My previous attempts at learning logic
programming have failed, and it just _feels_ like a thing that becomes clear
after you've seen how it works under the hood.

~~~
btwillard
Check out miniKanren ([http://minikanren.org](http://minikanren.org))!

~~~
thelazydogsback
Though as Kanren's biding-stream merging which is a bit different than
Prolog's DFS backtracking, it's good to look at but doesn't work like Prolog,
so one would still need to look at the latter separately.

------
soedirgo
Yarn 2 uses Prolog for workspace constraints.

[https://dev.to/arcanis/introducing-yarn-2-4eh1#workspace-
con...](https://dev.to/arcanis/introducing-yarn-2-4eh1#workspace-constraints)

------
carapace
I'm writing a constraint solver-based scheduler for lab work with social
distancing. It's going to be used by at least one lab.

(Reminds me I've got to get to work on it! Anybody ping me if you want to
help.)

------
The_rationalist
A tangeant question is: Which non-niche language are having push for
integrating a subset of logic programming extensions ?

There was a (unlikely to be merged at least in its current form) proposal for
Kotlin ->
[https://github.com/Kotlin/KEEP/pull/199/files](https://github.com/Kotlin/KEEP/pull/199/files)

Maybe LINQ from .NET could be included

There is also chalk from Rust [https://github.com/rust-
lang/chalk](https://github.com/rust-lang/chalk)

~~~
ahelwer
LINQ is just in-language SQL with type checks, unless I'm ignorant of a bunch
of its functionality (which I really hope is true, now).

~~~
tjalfi
There's a lot more to LINQ than that.

LINQ is extensible and you can connect it to arbitrary data sources by writing
a query provider.

awesome-linq[0] has some examples of what can be done with it.

[0] [https://github.com/aloisdg/awesome-
linq](https://github.com/aloisdg/awesome-linq)

~~~
ahelwer
Oh sure yeah, but I don't think it has any logic/constraint programming
functionality.

------
paloaltokid
Is this related to Datalog also? I've watched a few presentations by Rich
Hickey (creator of the Clojure programming language) and I feel like he often
name-drops Datalog as a great tool.

~~~
carapace
> Datalog is a declarative logic programming language that syntactically is a
> subset of Prolog.

[https://en.wikipedia.org/wiki/Datalog](https://en.wikipedia.org/wiki/Datalog)

------
tmaly
I have used Prolog in a few professional projects.

I think if they came out with a version in hardware like they use to have lisp
machines, it would have much better performance.

~~~
felixyz
That was one of the ideas of the Fifth Generation Computer Systems project,
started in 1982 :)

~~~
tmaly
timing was bad on that with the AI winter.

~~~
zozbot234
Wasn't the AI winter mostly a thing wrt. U.S. academia? 5th gen was a
Japanese-led industry project.

------
_neural_
To the degree that it counts as 'production' Prolog, DFS-Tools -- a toolkit
for Distributional Formal Semantics -- is actively used in a number of ongoing
scientific projects: [https://github.com/hbrouwer/dfs-
tools](https://github.com/hbrouwer/dfs-tools)

------
frompdx
I'm not a prolog or logic programming buff, but have you looked at something
like Clojure's core.logic?
[https://github.com/clojure/core.logic](https://github.com/clojure/core.logic)

------
brudgers
Any system that uses Datalog uses a subset of Prolog. Loosely, this would
include systems using Clojure's Datalog. To the degree the goal is logic
programming, the looseness is more appropriate. YMMV.

