Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a web application using LISP?

I have experience in C# and JavaScript, and have been working for the last few years with Node.js. Basically, I'm very confident with this environment, but one language has always caught my eye: LISP. I find it impressive and quite fascinating how expressive LISP is, given its minimal language concepts. It's basically as with jQuery: Do more with less ;-)

Unfortunately, my experience with LISP is more or less theoretical and some playing around, but not serious programming.

Now I'd like to change that, but I am definitely dedicated to web application development (hence Node.js). My problem is not to learn LISP as a language, my problem is that I do not know where and how to start with a "Hello LISP world" application that is not console-based, but web-based.

So, my question basically is: How could I write a server-side web application in LISP that is similar to the following Node.js application

var http = require('http');
http.createServer(function (req, res) {
  res.end('Hello world!');
}).listen(3000);

without the need for lots of frameworks and additional libraries and stuff and so on?

How would an experienced LISP programmer solve this task? Any hints?

like image 922
Golo Roden Avatar asked Aug 11 '13 14:08

Golo Roden


3 Answers

Once you have SBCL and Quicklisp installed,

(ql:quickload "hunchentoot")
(hunchentoot:start 
  (make-instance 'hunchentoot:easy-acceptor :port 3000))
(hunchentoot:define-easy-handler (foo :uri "/bar") (name)
  (format nil "Hello~@[ ~A~]!" name))

Then visit

http://127.0.0.1:3000/bar?name=World
like image 109
huaiyuan Avatar answered Sep 30 '22 09:09

huaiyuan


The answer about Hunchentoot is really a way to go for starters, and I fully recommend to try it.

The only major difference from the node.js variant in the question is that Hunchentoot is a synchronous web-server. If you want to get the same asynchronous behavior (actually, why would you, but that's for another discussion ;), you've got to try something else, like wookie. The similar Hello World example is procided at its documentation page.

like image 42
Vsevolod Dyomkin Avatar answered Sep 30 '22 10:09

Vsevolod Dyomkin


Just as to complement other answers, there are also ningle1 and caveman2, which also are decently documented. Ningle routing is very similar to Sinatra/Flask.

like image 30
PuercoPop Avatar answered Sep 30 '22 10:09

PuercoPop