DEV Community

Lucian Green
Lucian Green

Posted on • Edited on

Run List Prolog on the Web

A web editing studio (a computer-rended scene of curly chairs and glass tables in a dark cafe, without anything on the tables).
web-design-company-1142806

This is the second of two articles about Prolog development online. This article is about running and debugging Prolog algorithms on the web. (The first was about accessing computer files from a phone).

I will describe how to convert Prolog to List Prolog algorithms and run them.

  1. First download the Philosophy repository. This includes the Prolog-to-List-Prolog Repository.
  2. Next, download the SSI repository.
  3. In swipl (SWI-Prolog, which you also need to install), in the Philosophy folder, load ['run_lp.pl'].
  4. Start the server: run_lp_server(8000).
  5. Find your computer's IP address. On Mac, search for IP address (TCP/IP) in settings. If you are trying it out use localhost as the server.
  6. In your browser or on your phone, go to http://***IP address***:8000/a.

Figure 1. test.pl contains test:-member2([1,2],A),writeln(A).
Screenshot 2022-12-01 at 5 37 50 pm

Figure 2. test.lp (sic) contains [
[[n,test],":-",
[
[[n,member2],[[1,2],[v,a]]],
[[n,writeln],[[v,a]]]
]]
].

Screenshot 2022-12-01 at 9 40 30 pm

Figure 3. The web page reads: Run List Prolog (1 - Convert test.pl to test.lp and run query. 2 - Convert test.pl to test.lp. 3 - Run query.) Enter 1-3:
3

Prolog query for 1 or 3:
test.

Leash (on/off) for 1 or 3:
on

*.pl file for 1 or 2:
test.pl

*.lp file for 2 or 3:
test.lp
Screenshot 2022-12-01 at 5 37 28 pm

Figure 4. The web page with leash on reads:
[call,[[n,query_box_1],[]],'Press c to creep, s to skip or a to abort.'] [call,[[n,test],[]],'Press c to creep, s to skip or a to abort.'] [call,[[n,member2],[[1,2],[v,a]]],'Press c to creep, s to skip or a to abort.'] [exit,[[n,member2],[[1,2],1]],'Press c to creep or a to abort.'] [call,[[n,writeln],[variable]],'Press c to creep, s to skip or a to abort.'] 1 [exit,[[n,writeln],[1]],'Press c to creep or a to abort.'] [exit,[[n,test],[]],'Press c to creep or a to abort.'] [exit,[[n,query_box_1],[]],'Press c to creep or a to abort.']
Screenshot 2022-12-01 at 5 37 11 pm

Using this algorithm Prolog users can run their algorithms online without Prolog installed on their phone. They can enter queries and debug using the leash/trace feature.

Image by muradbd from Free Images

Top comments (0)