
Virtual machine inspection, now with added Prolog - rwmj
https://rwmj.wordpress.com/2015/12/06/inspection-now-with-added-prolog/
======
mmastrac
Awesome. Rules-based programming is one of those things that isn't useful
often, but when it is it can dramatically simplify a problem. It's worth
learning the basic structure of how prolog solves problems and internalizing
it (ie: the four-port model).

~~~
rwmj
My execution model is pretty simplistic. It basically does forward chaining
(not backtracking which is what a real Prolog interpreter would do). The
reason is that we have the core set of true terms up front, and we can just
run the rules to derive more and more terms until we hit the solution, and
because of the way the rules are written, we (hopefully!) won't get a
combinatorial explosion of terms.

This naive execution model is described here:

[https://github.com/rwmjones/libguestfs/blob/inspection-
exper...](https://github.com/rwmjones/libguestfs/blob/inspection-expert-
system/inspection/guestfs-inspection.pod)

under the section "Program evaluation".

~~~
ScottBurson
Looks like it's more like Datalog than full Prolog. [0] You are probably using
something similar to what is called the "semi-naive" evaluation strategy
(which despite the disparaging-sounding name is actually pretty good).

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

~~~
rwmj
Yes, I think you're right. I'm really exploring this for the first time since
university, and I don't have any real formal basis for what I'm doing. Just a
real world problem to solve.

------
alexchamberlain
Is embedding C necessary? I fear it could make the code substantially harder
to read, and doesn't really give a big benefit if you are transpiring to C
anyway. You could just link against a standard library.

~~~
rwmj
If I didn't embed C, many of the terms (eg. File, BlockDevice) would have to
be "magical".

