How to use Prolog with PHP?

南笙酒味 提交于 2019-12-24 18:50:29

问题


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


回答1:


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




回答2:


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:

  • 6 Mixing C/C++ and Prolog



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/1298723/how-to-use-prolog-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!