起初看起来有点反直觉,但我实际上建议制作一个基于Web的GUI.一旦你认为它通过(并检查了日食电的断点续传功能,http://eclipseclp.org/doc/bips/lib/http/index.html),你会意识到,Prolog是实际上是相当适合作为语言写一个应用程序服务器.我已经做到了非常成功,它避免了说服某人查看非标准UI框架的艰难战斗.此外,它可以立即实现移动,并且可以很好地区分问题.
这是一个极简主义的例子.当您运行它(eclipse -s http.pl然后调用runserver)时,您可以在localhost:8000上打开浏览器以调用下面processURL中定义的路由谓词:
http.pl:
:- lib(http),
use_module(http_method).
runserver :-
http_server(8000).
Run Code Online (Sandbox Code Playgroud)
http_method.pl:
:- module(http_method).
http_method("GET", Url, Params, Contents, 200, [contentLength(CL), contentType(mt(text, html))]):-
printf("%w\n", [http_method(Url, Params)]), flush(output),
http_process(Url, Contents),
string_length(Contents, CL).
http_process(Url, Contents) :-
split_string(Url, "/", "/", L),
printf("URL split: %w\n", [L]), flush(output),
processURL(L, Contents).
processURL([""], "Hello World!").
processURL(["route1"], "You are at /route1").
Run Code Online (Sandbox Code Playgroud)