Home Programmierung A Simple Lisp Web Repl

Main Menu

Texte / Essays
A Simple Lisp Web Repl


As a Business and Systems Analyst, I sometimes find it useful to write little tools that check databases, create test data or analyse or compare files or configurations and so on. Most of the time I use Lisp and the Repl, sometimes perl. There are situations in which I´d like to make my Lisp test functions available to my colleagues or customers, but, however, working with Emacs and learning to work with the Repl would be too big of a step for most not familiar with Lisp.

I asked myself: what would be a simple, direct and transparent way to make functions and evaluation of functions available to anyone not familiar with Emacs and the REPL? I would create a file with some Lisp functions, but there is no time for any kind of GUI. However, a web browser and a few lines of generic HTML should do the job.



For that purpose I created the “Web-Repl”. I wrote a local webbased Repl using Hunchentoot and a few parsing functions which allow to load a Lisp file and evaluate functions with a generic Web Interface.  The Web-Repl displays a file with Lisp Function Definitions in the web browser and includes POST forms to fill in the function parameters and a “Eval” Button; it then shows the evaluation result in the browser, just like the Repl would.

My environment is Clozure Common Lisp and Windows. The Web-Repl requires Hunchentoot, cl-who, cl-fad, cl-ppcre. Please note: this program is not designed for security, use it only in trusted environments.

Here is the [ Source Code ] for use with ASDF.

Instructions: First edit the Config File “setup.lisp” to set the path for the Repository and local Web port, then load the web-repl via ASDF. Change to package web-repl and start it in the package via “(web-repl-setup)”. As a convenience, I use “ccl:run-program” with parameters “explorer” and the local URL as parameter, which should open the default Webbrowser in Windows and show the “Main Menu”.




As I noted in earlier posts, I consider myself still a Lisp beginner, and there is certainly room for improvement in my code. But creating the Program was fun and it does what I wanted it to.


  • In “dir-html2” I parse the directory from repository root directory *repo-root* and show it as a kind of “Main Menu”

  • For each file there are different transactions: display only function names, display the source (in case the user is interested in it) or Display the File with prepared Forms to evaluate functions (“Use”) –this is the Web Repl. There is even a simple “Edit” Function –it opens a batch file with notepad.exe with the file name as argument (or anything else you put in the batch file referenced by *webgui-editor*) via “ccl:run-program”. (For some reason, starting external Windows GUI programs via “ccl:run-program” requires a batch file in CCL.)

  • Evaluation happens in function “lispfile-view3” (please forgive me my function naming strategy);  I first load the Lisp file; if errors occur, I want them to be displayed in the Web Browser, so Hunchentoot is configured that way (show-errors and backtrace is true). If “state-variable” is set, then a POST was performed, so I set “returnval” to the evaluation result of the function call including parameters via read-from-string. 

  • Next, a List of the Lisp Functions of the file is prepared; if there is an evaluation result, it is shown, together with the called Function; finally, the lisp function list together with forms is displayed. 

  • “prepare-defuns” returns al list of defuns together with Arguments and Documentation.  The trick to find out Function Parameters is using “ccl:arglist” together with “find-symbol” which returns the parameters required for a function; I also use “documentation” the same way, together with find-symbol, to get the Documentation string. I could have parsed this information from the file, but as the Lisp File is loaded before, Lisp has it, so I use the built-in functions.


The Rest of the Functions are only Help Functions; some functions are inspired by the Hunchentoot Example Code, which I found very useful.

One current limitation: anything that is returned for display in the web-browser is not yet prepared, so if the strings contains “<” or “>” the browser will not display it correctly.