
A Couple of Meta-Interpreters in Prolog - octosphere
https://www.metalevel.at/acomip/
======
triska
Thank you very much for the publicity, I greatly appreciate it!

Prolog is rather unique in that it admits a meta-interpreter in roughly 3
lines of code. Contrast this with other languages, where writing an evaluator
typically takes much more code, even for quite high-level languages.

This brevity is possible mainly because Prolog - like Lisp and assembly
language - is a _homoiconic_ language, and in addition to that, Prolog has
powerful built-in mechanisms that can be used in interpreters, and in addition
to _that_ , Prolog variables on the object-level (the program to be
interpreted) are also variables on the meta-level (the interpreter). As a
consequence, Prolog's implicit mechanisms can be _absorbed_ in interpreters:
They need not be encoded explicitly.

Enjoy!

~~~
3rdAccount
Can you explain to me what you use Prolog for and why you chose it over
something more popular? What are the pros/cons in your mind?

Everytime I get started, I eventually stop when I realize I'm not an alien
named Spock :). In all seriousness, it is very challenging to me, so kudos to
you. My bucket list has Forth, APL, Lisp, Smalltalk, and Prolog on it.

~~~
triska
Learning Prolog was very challenging for me too! I was extremely lucky though
in that I had one of the world's greatest Prolog experts as instructor, using
the world's most sophisticated Prolog teaching environment:

[https://www.complang.tuwien.ac.at/ulrich/gupu/](https://www.complang.tuwien.ac.at/ulrich/gupu/)

You can take a short pictorial tour of GUPU:

[https://www.complang.tuwien.ac.at/ulrich/gupu/d-2-europastad...](https://www.complang.tuwien.ac.at/ulrich/gupu/d-2-europastadt-
dax)

However, these pictures can at best give a small glimpse of what GUPU actually
is, so I also recommend a longer paper:

[https://www.complang.tuwien.ac.at/ulrich/papers/PDF/gupu-
wlp...](https://www.complang.tuwien.ac.at/ulrich/papers/PDF/gupu-wlpe2002.pdf)

For me, a major attraction of Prolog is the _balance_ it strikes between
readability, versatility and convenience. I know languages that sometimes
admit shorter programs, but they then are - at least in my experience - not as
readable as a Prolog version, or not as versatile.

I am using Prolog for many different tasks, such as hosting web pages,
prototyping showcases, and solving combinatorial optimization problems.

~~~
3rdAccount
I have to make extensive use of Linear Programming & Mixed-Integer Linear
Programming in my day job. This all runs on CPLEX. It would be really cool to
do that sort of thing in Prolog, but I doubt it could handle massive models.
Anyway you could explain what combinatorial optimization is for and how it
differs from the things commonly seen in operations research?

~~~
triska
For solving linear programs and mixed-integer linear programs with Prolog, I
recommend the CLP(Q) and CLP(R) libraries of SICStus Prolog. See for example:

[https://sicstus.sics.se/sicstus/docs/3.7.1/html/sicstus_32.h...](https://sicstus.sics.se/sicstus/docs/3.7.1/html/sicstus_32.html)

For discrete optimization tasks, also check out the integer constraint solver
that ships with SICStus Prolog. See especially the combinatorial constraints:

[https://sicstus.sics.se/sicstus/docs/4.1.0/html/sicstus/Comb...](https://sicstus.sics.se/sicstus/docs/4.1.0/html/sicstus/Combinatorial-
Constraints.html#Combinatorial-Constraints)

As to the relation between Prolog and operations research: Prolog systems
_internally_ use methods from operations research to efficiently solve
optimization tasks; in addition to that, you can of course also implement
every OR algorithm in Prolog.

For many commercial users of SICStus Prolog, the efficiency of its constraint
solvers are an important reason for buying a licence.

------
YeGoblynQueenne
I know this is not the done thing, but a meta-interpreter is the best,
easiest, simplest way I've found to explain resolution (for maximum impact,
you can trace a program through the meta-interpeter so the other person gets
to see what's going on).

And if I can be allowed a shamless plug of my research team's work, it's also
possible to turn a meta-interpreter to an inductive learning procedure, so
that you can generate a new program from examples of its inputs and outputs,
even as you prove it. It's called Meta-Interpetive Learning:

[https://github.com/metagol/metagol](https://github.com/metagol/metagol)

~~~
mycl
Sorry to be rude, but could you ask/beg Prof Muggleton to write a book on ILP
and/or meta-interpretive learning? Something like an expanded version of his
outline webpage
([https://www.doc.ic.ac.uk/~shm/ilp_theory.html](https://www.doc.ic.ac.uk/~shm/ilp_theory.html)).

My go-to for trying to understand ILP theory is Nienhuys-Cheng and de Wolf,
_Foundations of Inductive Logic Programming_ and De Raedt's _Logical and
Relational Learning_ is a more up-to-date overview, but I feel like there's
room for a more modern textbook. This new MIL stuff seems to be be an
important unifying idea that also connects back to abductive logic
programming, if I understand correctly.

Just a request; no offence intended!

~~~
YeGoblynQueenne
Not rude at all! There are precious few textbooks on ILP, it's mostly a bunch
of scattered papers published in various journals and conferences. Nienhuys-
Cheng and de Wolf are an excellent first point of call. You can also try the
following books:

Logical and Relational Learning - Luc de Raedt
[[https://www.amazon.com/Logical-Relational-Learning-
Cognitive...](https://www.amazon.com/Logical-Relational-Learning-Cognitive-
Technologies/dp/3642057489)]

Probabilistic Inductive Logic Programming, Theory and applications - Luc de
Raedt, Paolo Frasconi, Kristian Kersting, Stephen Muggleton
[[https://www.amazon.com/Probabilistic-Inductive-
Programming-L...](https://www.amazon.com/Probabilistic-Inductive-Programming-
Lecture-Computer/dp/3540786511)]

And this book chapter (although it's probably nothing new compared to
Foundations of ILP):

Inductive Logic Programming: Theory and Methods - Stephen Muggleton and Luc de
Raedt
[https://www.sciencedirect.com/science/article/pii/0743106694...](https://www.sciencedirect.com/science/article/pii/0743106694900353)

Unfortunately, there are, as of yet, no textbooks on Meta-Interpretive
Learning and I don't expect there to be one for a few years still. MIL is a
very new area of research. The first papers were published only in 2015 and we
are basically still working on it furiously. It will take a while before there
is enough material for a textbook. All the same, I am planning to do a few
internet postings regarding MIL, at some point in the near future.

Please feel free to contact me via my profile email, if you would like some
pointers to MIL and more general ILP resources other than the ones discussed
above.

~~~
mycl
Thanks for the pointers! I look forward to your postings.

