tags:

views:

1980

answers:

7

As a long time PHP programmer I was looking for a more powerful language for our next project. And thus got interested in Lisp.

Now I am finding that, unlike PHP, most Lisp compilers have to run beside the web server as a service. But Reddit experience says that they had to always monitor the service from crashing. In PHP we never had to care for this thing. The other solution might be to use Lisp as CGI. But then we are travelling uncharted territory and I am not sure if that is even preferred or anyone tried it.

Others have proposed to use Clojure. An excellent choice which brings in all Java libraries. But the problem is it's Lisp-1, and not Lisp-2. The only reason why we are trying to use Lisp is because of its powerful multi paradigm coding language where one start to feel the benefit as software gets more and more complex. I am not sure how much of this benefit will be sacrificed by switching to Scheme instead of Common Lisp.

Someone even mentioned here in stackoverflow that the difference between Scheme and Lisp is like Java and C++. To a lisper both Java and C++ look almost the same.

Now back to my question/

  1. What is the modern preferred way to develop Lisp application and deploy it?
  2. Which Lisp compiler are you using for web applications?
+6  A: 

This thread suggests that running your app inside GNU screen is a popular way. But there's many different approaches. I think most Lisp web libraries are themselves web servers, so you don't need a separate "web server" process unless (or until) it provides something you need.

If Clojure meets your needs, then go ahead and use that. (I've never used it because it hasn't met mine, but yours are obviously different.) It's not Scheme, and I'm not sure what specific problems a Lisp-1 has, so I don't know what problems you're anticipating there. My impression has been that a Lisp-1 is simpler, but a Lisp-2 makes it easier for compiler writers to generate more efficient code. I doubt my code relies on CL being a Lisp-2 at all, apart from needing FUNCALL and APPLY.

I'm using SBCL, but since it's Common Lisp, any CL compiler would work. At times I've used CLISP in testing.

Ken
+10  A: 

I am using Common Lisp (SBCL) for a tiny website I designed, using Hunchentoot. Hunchentoot can either listen on port 80 or you can use Apache and mod_proxy as a frontend to Hunchentoot running on some other port. To keep Lisp running in the background you can use GNU screen or something like detachtty which is similar but more lightweight. You will probably have the fun of writing your own init scripts to start your server at boot time, and other such niceties.

Common Lisp is showing its age and you will face difficulties using it. By contrast Clojure is very new and not as stable or mature as other languages. Hard choice. I am planning to switch to Clojure partly because Common Lisp isn't a joy to deploy and partly because of how much of a joy Clojure has been for me to use thus far. Took me quite a long time even to get SBCL running on a VPS server, never mind the libraries. Clojure will run anywhere the JVM runs. But your mileage may vary.

A website takes a request and returns some text to display in a browser. Alternately it may access some shared resources server-side in a multithreaded way. This is the kind of thing Clojure was designed for, in my opinion. There are some good web frameworks for Clojure already (e.g. Compojure). Clojure is not Scheme by a long shot. Very different design philosophies.

I tried and failed to get Hunchentoot to work with FastCGI. I think Lisp as CGI is going to be painful. But again your mileage may vary.

Brian Carper
I can not follow the arguments about Lisp showing it's age. One of the first fully fledged HTTP-Servers were implemented with Common Lisp. Seehttp://www.cl-http.org:8001/cl-http/ AllegroServer is used in production use at http://franz.com
Friedrich
An example of age: Unicode support (http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/97ff103aee76ada2#). My site uses CL too; that's an anecdote, doesn't mean anything. I could get a site working in anything if I put in enough effort. CL is not in common use for web design.
Brian Carper
+1  A: 

Using Common Lisp via CGI is certainly possible. After all, my blog has been served by a CGI Lisp programme for some time now. If I had a choice, I'd go with the persistent process, though. Interactive programming works much better that way.

Matthias Benkard
+3  A: 

Using Hunchentoot with or without Apache, as suggested by Brian C., is probably your best approach if you're doing anything complex. It's really easy to do CGI with Common Lisp, though, especially with CLISP, and there are several libraries out there that will help you. One example is lisp-cgi-utils, and there are others, none of which are fancy but all of which are about equally effective. My webhost doesn't allow persistent Lisp processes, so I've used CLISP and lisp-cgi-utils with some pleasure.

Clojure sounds like a good thing - but I've never used it myself; its newness makes me nervous.

JasonFruit
+3  A: 

Ok check out 1) UCW 2) AllegroServer + Webactions 3) Hunchentoot 4) mod_lisp and apache 5) http://weblocks.viridian-project.de/ 6) http://www.cliki.net/bknr

I guess one of them will be to your liking.

Friedrich
+14  A: 

I've written several web applications in Common Lisp, one of which is currently deployed and making money (a charter airline reservation system that surprisingly has nothing to do with ITA), and others which are either still under development (a financial modeling system for large oilfield projects - I left but they signed up with a prominent VC firm a couple of months ago, next-gen trading/TA platform for futures and commodities - my current project) or were mothballed but are good business ideas (a web "reverse proxy" for advertisers and bolt-on solutions to fixing web apps that you can't fix any other way, I'm still interested in developing this).

As a result I have some experience in deploying Lisp web apps, however as you can see it is heavily biased towards high-performance Intranet apps with not that many users, and particularly the need to make the web browser experience feel as responsive as a desktop app. If my current project goes according to plan I should have the opportunity to test my approach on a high-traffic public website.

This is how I set up Lisp web applications:

Everything (including static content like images) is served straight from Hunchentoot running on SBCL on Linux. Hunchentoot uses a thread-per-request model, which is exactly what my web apps need. SBCL on Linux uses NPTL, which according to some benchmarks makes thread-per-request faster than futzing with NIO. I haven't done my own benchmarks, but I'm not worried about Hunchentoot keeping up as a web server.

I start SBCL inside GNU screen using setuidgid to have it run under a locked-down, non-privileged account and still have access to the REPL for upgrading the system without service interruptions.

All the HTML generation is done by CL-WHO. I have my own Lisp-to-JavaScript compiler called Parenscript. On the oilfield modeling project we evaluated pretty much everything out there for writing web apps and settled on doing our own by adopting Parenscript from its previous maintainers. Writing web apps that perform like desktop apps is difficult - the difference between something that feels "native" and something that is unusable junk is usually a couple of lines of code. Finding the right couple of lines without being able to generate and instrument JS code in an intelligent way is a huge task.

For storage I use the CLSQL library. It has a really goofy syntax for writing first-class SQL queries (ie - real objects and not just strings) in Lisp, but after using it I think it's more trouble than it's worth. For the reservation project I wrote some macros that took a business object description and generated SQL schemas (really straightforward ones using SQL types without any kind of Lisp encoding or metadata), functions to produce HTML forms for inputting and editing those objects, and POST handlers for handling and verifying those form submissions while dealing with multiple-submit and CSRF issues. That turned out really RESTy.

Whoever claims this setup is unreliable has some severe problems with their servers. The reservation system I designed has been running for over a year with the only downtime being due to hardware failure.

Neat things that I've easily done with this approach:

  • Comet (just ask Hunchentoot for the stream and keep writing to it)
  • Compile-time intra-application link checking (see my blog entry)
  • Portable profiling for all of your JS code
  • Generating versioned, browser-specific JS and content resources that are perfectly cacheable

I dislike frameworks, preferring the Unix ideal of putting together orthogonal tools, so I can't really recommend either UCW or Webactions.

I use CL-WHO because most of the HTML in those applications is generated. If you have a document-oriented web app and someone dedicated to doing HTML and CSS you'll probably want some kind of template system.

One thing you need to watch out for when deploying is the issue that Brian Carper mentioned with VPSs. The main culprit seems to be Virtuozzo - their virtual memory system can't handle overcommitment on any but the host instances. SBCL does this, but other implementations with different memory management strategies won't have this problem. FYI the reservation system is actually deployed on host VZ instances.

vsedach
+1  A: 
  • What is the modern preferred way to develop Lisp application

Subjectively using Vim, rlwrap and SB-ACLREPL as tools. Weblocks, cl-prevalence and Elephant for frontend and storage.

  • and deploy it?

Run your favorite Lisp within tmux, GNU Screen or detachtty on a VPS or dedicated server. Attach to process as needed. Load changes with ASDF.

  • Which Lisp compiler are you using for web applications?

SBCL, maybe also Clozure in the future.

skypher