Skip to content

kloimhardt/lisp-webscript-examples

Repository files navigation

lisp-webscript-examples

Lisp like its Javacript+PHP (yes, needs PHP installed)

Examples for programming small reactive web-apps in Lisp. Back- and frontend use Clojure inspired Lisp interpreters: Phel and Scittle. Because the interpreters run on PHP and Javascript respectively, the code can be deployed on cheap shared web-hosting.

There are two examples, both canonical: Guestbook and Todo-MVC. They show how to administer the interplay between frontend and backend the Clojure way. While Guestbook (taken directly from the Luminus book) is simpler and has a more traditional REST api, Todo-MVC has an advanced GraphQL api via Qlkit

Setup

You need to install PHP 7.4 (or later) and download the file composer.phar into the directory of the cloned repository. Then, download Phel with:

php composer.phar install

delete the /out directory and compile the project with

rm ./out
./vendor/bin/phel compile

Start a server with:

php -S localhost:8000

if you want to do development without the compilation step, you need to uncomment the first five lines in index.php and delete the rest of the lines.

Guestbook

To try the Guestbook example, type in the adress bar of your browser:

http://localhost:8000/?guestbook

The Phel and Scittle code are in the files phel/guestbook.phel and cljs/guestbook.cljs, both sport the Clojure(Script) syntax and the goodness of persistent data structures.

Todo-MVC

You need to have the MySql database installed. You also need to replace the connection string in the file mysqldsn.txt. Then, start with

http://localhost:8000/

The code in little-clojure/honey-sql.phel implements a very small subset of HoneySQL which translates Clojure/Phel datastructures (like {:select [:id] :from [:todos]}) into SQL strings.

The code in little-clojure/core.phel contains a crude imitation of Clojure multimethods, which are necessary for implementing Qlkit's parsers.

Technical Note

I needed to expose Qlkit to Scittle (see branch clj-ajax-plugin, scittle/src/scittle/qlkit.cljs). All of this Clojurescript code is compiled into publicly served Javascript files, but can be self-compiled following the Scittle instructions.

Moreover, the 60 loc server part of Qlkit had to be ported to Phel.

Run Tests etc.

./vendor/bin/phel test
./vendor/bin/phel format phel
./vendor/bin/phel format tests

About

Examples for scripting reactive web-apps in Lisp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •