在 Lisp 中进行(严肃的) web 开发是否可行?

显然,可以用几乎任何编程语言编写几乎任何类型的应用程序,尤其是像 Lisp 这样强大的语言(无论是 Scheme 还是 Common Lisp)。但是,将它用于 Web 开发是否切实可行呢?如果是这样,什么应该是一个良好的起点?在哪里可以找到适合这种性质的项目的资源(工具、库、文档、最佳实践、示例等) ?

29537 次浏览

Paul Graham's company Viaweb wrote a product in Common Lisp that subsequently became Yahoo Shops. Apparently Yahoo subsequently re-wrote it in C++. There are quite a few web resources for Lisp progamming.

Have a look at Allegro Common Lisp. It has some libraries, including a web server, specifically for web development.

You can find some stuff about tooling for Lisp web applications in this question.

It might also be worth having a listen to Stack Overflow Podcast 27 where the Reddit guys talk a bit about their experience of runnig a website on Lisp (and their switch to Python).

I think one can say yes without much hazzle.

  1. one of the first HTTP server was cl-http

  2. The scheme people around DrScheme have spent a remarkable amount of time on it:

  3. www.franz.com runs on their own Webserver (AllegroServer) and webframework (webactions)

  4. If you are in doubt check the common lisp packages from Edi Weitz. They usually work.

So yes one can do "serious" web-programming with Common Lisp. I for my part am currently undecided to follow some Common Lisp route or Ruby on Rails. I prefer both over anything .NET....

Opinions vary. The common wisdom is: Better use a different language, or rather a different web stack, such as LAMP, .NET, Ruby on Rails, Java. The well-known successful web project in lisp was Paul Graham's ViaWeb. Reddit was initially implemented in lisp, but then switched to python. If you do decide to use lisp, try Seibel's book: Practical Common Lisp.

There are some web frameworks out there for web development. Have a look at:

If you want well supported lisp tools then you'll need to pay for them. There just isn't a very big community around the open source tools so they don't have the same level of documentation/adoption as, say, Django on Python.

Here are some commercial lisp products:

Its also worth noting that Reddit was initially built in Lisp, but the authors later migrated to Python, citing a lack of well used and documented libraries. (link)

Yes, web development is one of Common Lisp's strengths today.

  • As a web server, use Hunchentoot, formerly known as tbnl, by Dr. Edmund Weitz.

    You can run it as a back-end to Apache using mod_proxy as a reverse proxy, or as a stand-alone server.

  • Various HTML generation solutions are available, from PHP-style templates to Lisp macro hacks to XSLT. Just take your pick.

    HTML-TEMPLATE is one example.

  • Closure XML is available for XML parsing, serialization, XPath 1.0, XSLT 1.0. There is also Closure HTML for HTML tag soup parsing.

    (Full disclosure: I'm the maintainer of Closure XML and Closure HTML.)

  • If you like, Parenscript can make your JavaScript experience lispier, but you can also write plain old JavaScript yourself, of course.

    Another cool JavaScript enhancing solution in jwacs, which is written in Common Lisp and transforms JavaScript to add continuation support.

  • Web service projects might require an HTTP client in addition to a server.

    Drakma is the library to use for that today.

    PURI is useful for URI manipulation.

    And there is more! One starting point is cliki, for example cliki.net/web.

On the web, nobody knows your server is written in Common Lisp :-)

Web development in Common Lisp is both effective and fun.

Some examples:

CL-WHO allows you to write HTML without forgetting a closing tag ever again.

Weblocks lets you define forms declaratively with built-in validation:

(defview signup (:type form :caption "Sign up")
(username :satisfies #'valid-username)
(password :present-as dual-password :parse-as dual-password)
(receive-newsletter-p :present-as checkbox :parse-as predicate))

It also supports AJAX in a fully automatic manner, falling back to normal links if the browser doesn't support it.

cl-prevalence is an incredibly simple alternative to SQL.

Quite a lot of people are using these technologies lately for mission-critical applications -- with success.

Most important CL open-source projects in fact do have excellent community support.

Looks like a lot of Orbitz was or is written in LISP.

I can't speak to other frameworks, but I've had very good luck using Hunchentoot for a webserver (it works fine on its own, or you can put it behind Apache). What really makes it shine (this will probably come as a shock to some) are the libraries!

  • Use CL-WHO to write effortless HTML in a lisp-style syntax
  • Parenscript allows you to write code that compiles to javascript
  • For database connectivity use Postmodern to talk to PostgreSQL

What I really like about using CL for the web is that you can tweak it all as it is running. You always have a REPL up and running your server code, you can then connect to that REPL and change or inspect how the code is working, all without having to stop anything. I've redefined functions while the site is running, the next time the function is called, it simply picks up the new code and works.

To further help dispel the myth that there are no Lisp web frameworks, here are ones that have not yet been mentioned:

Obviously a lot of people seem to think Lisp is good enough for writing a lot of web frameworks.

I don't use or endorse any web frameworks. I prefer to build web applications by combining together orthogonal tools (David Lichteblau has mentioned some good ones) using design patterns in a way that is actually appropriate to the application you are building, and that is the approach I recommend. Common Lisp provides both a wealth of such tools, and an unmatched ability to combine them.

Adam Petersen published an excellent introductory tutorial for how to start building Lisp web applications in this style last year:

http://www.adampetersen.se/articles/lispweb.htm