How to use Prolog with PHP?

I want to use Prolog with PHP. Is it possible?

0
source share
4 answers

There are always exec-familiy functions to execute / create another process.

+3
source

As suggested above, you can run a Prolog interpreter or binary. However, most Prolog implementations also export a C API that can be used to invoke the Prolog interpreter.

You can create a small PHP module to run the interpreter and execute queries. For example, the SICStus documentation describes in detail the use of Prolog from C:

+2
source

- . PHP, - , .

+1

I wrote a translator that can convert some simple PHP programs to Prolog.

This is a possible input program:

function is_greater_than($a,$b){
    return $a > $b;
}
function is_an_animal($a){
    return in_array($a,["dog","cat"]);
}

... and this is the output program:

is_greater_than(A,B) :- 
    A>B. 
is_an_animal(A) :- 
    in_array(A,[1]).

This translator is just a proof of concept, but it can still simplify the conversion of some simple PHP programs to Prolog.

+1
source

All Articles