Jurassic.pl

https://github.com/haldai/Jurassic.pl

Run Julia codes in Prolog.

Features

?- := println("Hello World!").
% output
% Hello World!
% true.

?- a := sqrt(2.0),
     := println(a).
% 1.4142135623730951
% true.
?- f(x) := x*transpose(x).
% true.

?- := @show(f([1,2,3,4,5])).
% f([1, 2, 3, 4, 5]) = [1  2  3  4  5; 
%                       2  4  6  8 10; 
%                       3  6  9 12 15; 
%                       4  8 12 16 20; 
%                       5 10 15 20 25]
% true.

?- := cmd("function fib2(n)
               n <= 1 && return 1
               sum = 0
               while n > 1
                   sum += fib2(n-1)
                   n -= 2
               end
               return sum + 1
           end").
% true.

?- := @time(@show(fib2(46))).
% fib2(46) = 2971215073
%   4.409316 seconds (60.55 k allocations: 3.183 MiB)
% true.
?- f(x) := sqrt(x) + x^2 + log(x) + 1.0.
% true.

?- X := f(2.0).
% X = 7.10736074293304.

% Prolog and Julia work together
?- between(1,10,X),
   Y := f(X).
% X = 1,
% Y = 3.0 ;
% X = 2,
% Y = 7.10736074293304 ;
% X = 3,
% Y = 12.830663096236986 ;
% ...
% Wrapping tuples with predicate tuple/1, 
% and passing datatypes (e.g. Int32) as atoms:
?- := @show(ccall(tuple([:clock, "libc.so.6"]), 'Int32', tuple([]))).
% ccall((:clock, "libc.so.6"), Int32, ()) = 947332
% true.

More examples please refer to this link.