DEV Community

Lucian Green
Lucian Green

Posted on • Edited on

How to Create a Small Web App with SSI Web Service

I will break down the steps to create a web app with State Saving Interpreter Web Service, an interpreter written in Prolog that runs List Prolog.

  1. Convert the Prolog algorithm to List Prolog

I installed Prolog-to-List-Prolog from https://github.com/luciangreen/Prolog-to-List-Prolog.

In a new file, test1.pl in the Prolog-to-List-Prolog folder, I entered:

cultivate_person(A,B).
cultivate_person(A,B):-writeln("Do you create the person?"),read_string(A),writeln("Do you switch them on to existing for the rest of their life?"),read_string(B).

Then:
['p2lpconverter.pl'].
['../listprologinterpreter/listprolog'].
p2lpconverter(A),pp0(A,B),writeln1(B).

The output is:

"[
[[n,cultivate_person],[[v,a],[v,b]]],
[[n,cultivate_person],[[v,a],[v,b]],"":-"",
[
[[n,writeln],[""Do you create the person?""]],
[[n,read_string],[[v,a]]],
[[n,writeln],[""Do you switch them on to existing for the rest of their life?""]],
[[n,read_string],[[v,b]]]
]]
]"

  1. Modify ssi-api.pl and Run Application

I installed SSI from https://github.com/luciangreen/SSI.

In a new file test1.pl in SSI I entered:

test1([[n,cultivate_person],[[v,a],[v,b]]],

    [[[n,cultivate_person],[[t,string],[t,string]]]],
    [[[n,cultivate_person],[output,output]]],
Enter fullscreen mode Exit fullscreen mode

[[[n,cultivate_person],[[v,a],[v,b]],":-",
[
[[n,writeln],["Do you create the person?"]],
[[n,read_string],[[v,a]]],
[[n,writeln],["Do you switch them on to existing for the rest of their life?"]],
[[n,read_string],[[v,b]]]
]]]).

This includes the output from the first step and optional type and mode statements. Note: two double quotes have been replaced with one. Also, the query was cut from within the brackets as you can see.

In ssi-api.pl, I changed:

test_open_types_cases(4,Query,Types,Modes,Functions),
international_lucianpl([lang,"en"],Debug,Query,Functions,Result1),

to:
test1(Query,Types,Modes,Functions),
international_lucianpl([lang,"en"],Debug,Query,Types,Modes,Functions,_Result),

Then:
[ssi].
[test1].
ssi_server(8000).

In my web browser, I visited my localhost at http://127.0.0.1:8000/.

And here is an image of the first page of the web app in the browser:
(It reads:
http://127.0.0.1:8000/
Do you create the person?
[Text Box]
Submit Button)

Screen Shot 2022-02-21 at 12 12 57 am

Author: Lucian Green
SSI: https://github.com/luciangreen/SSI

Top comments (0)