Interface between Julia and SWI-Prolog

Hi, I have developed an interface between SWI-Prolog and Julia, here is the link:

This package is inspired by real, but I believe Julia is more modern, efficient and easy-to-use, and it is getting popular in data science and machine learning. The README in my GitHub repo should cover most of the basic usages.

For now, it can:

  • Unify Julia variables with Prolog terms;
  • Store external data (e.g. vectors, matrices, images), not just logical facts, in Prolog, and handling heavy computations;
  • Import Julia packages. So it can plug in and train machine learning models as Prolog predicates via ScikitLearn, Flux, TensorFlow and Knet (with cuda);
  • Call Python libraries by PyCall or call C/Fortran functions through ccall from shared libraries directly;

I had just started it so it will contain a lot of bugs. Should you find any problem, please fire an issue on the Github page. Any comments or ideas of new functionalities are welcomed!


I would suggest you make it a pack, that way it will be much easier to install and build for the prolog community:


Instead of using kw(Key, Value) for keyword arguments, why not just use Key=Value? It is much closer to Julia, and it is just as easy to do from the prolog point of view.

By the way, I find your package really useful for quickly plotting and analyzing data. Thanks!

Great resource. Note that if calling C is your target you can also use the ffi pack (which also contains demo code to call Python)

1 Like

Thank you for the suggestions, I am using kw/2 because inside of Julia the keywords assignments in functions are parsed as Expr(:kw, :Key, :Value) rather than Expr(:=, :Key, :Value). But I agree that it is not difficult to make them more natural.

I will update and make the interface available as a pack soon!

Thank you very much! I will try the ffi pack, it looks awesome!

On the repo readme file you wrote:

This package is only tested on Linux, not sure if it will compile on MacOS (maybe) or Windows (very unlikely).

After installing Julia using MacPorts, replacing all references to .so libraries with .dylib in the repo files and running make, all the examples I tried from the readme file work as expected :slightly_smiling_face:

Thank you so much for testing! I’ll try to revise the code to make it compatible with both Linux and Mac in the next version :grinning:

1 Like