How to use Prolog with PHP?

2019-08-28 22:17发布

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

标签: php prolog
4条回答
倾城 Initia
2楼-- · 2019-08-28 23:06

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

查看更多
趁早两清
3楼-- · 2019-08-28 23:15

Most Prologs allow for prolog code to be compiled into a binary. You could try calling this binary from within PHP using some kind of process call as already mentioned.

查看更多
【Aperson】
4楼-- · 2019-08-28 23:18

I wrote a translator that can convert some simple PHP programs into Prolog and vice-versa.

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) :- 
    member(A,["dog","cat"]).

This translator is only a proof-of-concept, but it may still make it easier to convert some simple PHP programs into Prolog.

查看更多
一纸荒年 Trace。
5楼-- · 2019-08-28 23:19

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

You could create a small PHP module to start an interpreter and execute queries. For instance, the SICStus documentation describes using Prolog from C in detail:

查看更多
登录 后发表回答