Run List Prolog on the Web
Tags: list, prolog, web
Published: 2022-12-01 07:00:53

---
title: Run List Prolog on the Web
published: true
description: Develop and run List Prolog algorithms on the web
tags: list, prolog, web
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2022-12-01 06:28 +0000
---

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](https://user-images.githubusercontent.com/15845542/204984193-ae426560-1f13-46f1-8804-5a6c3b848fc1.jpg)

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 <a href="https://dev.to/luciangreen/access-your-computers-files-from-your-phone-i5">accessing computer files from a phone</a>).

I will describe how to convert Prolog to List Prolog algorithms and run them.
1. First download the <a href="https://github.com/luciangreen/Philosophy">Philosophy repository</a>.  This includes the Prolog-to-List-Prolog Repository.
2. Next, download the <a href="https://github.com/luciangreen/SSI">SSI repository</a>.
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).`
<img width="594" alt="Screenshot 2022-12-01 at 5 37 50 pm" src="https://user-images.githubusercontent.com/15845542/204982965-1b34f37e-ba79-4a20-a1e2-f970953b8bce.png">

Figure 2. `test.lp` (sic) contains `[
[[n,test],":-",
[
	[[n,member2],[[1,2],[v,a]]],
	[[n,writeln],[[v,a]]]
]]
].`
<img width="525" alt="Screenshot 2022-12-01 at 9 40 30 pm" src="https://user-images.githubusercontent.com/15845542/205032090-bb82644b-8960-4b5b-96f6-98e845280a14.png">

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
<img width="496" alt="Screenshot 2022-12-01 at 5 37 28 pm" src="https://user-images.githubusercontent.com/15845542/204982978-facf8dd2-44e8-4e95-bcfa-9287a3fbbaf8.png">

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.']
<img width="499" alt="Screenshot 2022-12-01 at 5 37 11 pm" src="https://user-images.githubusercontent.com/15845542/204982984-1dacdc6e-a931-48eb-8b3e-3da3d4598f2e.png">

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