npsimons / land-of-lisp-using-hunchentoot

Convert code for "Dice of Doom" from Barski's "Land of Lisp" to use Hunchentoot web server.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Land of Lisp" using Hunchentoot

Convert code for "Dice of Doom" from "Land of Lisp" to use Hunchentoot web server for version 3 and 4.

I recently went through "Land of Lisp" by Conrad Barski, a thoroughly enjoyable book! Unfortunately, I couldn't get the web server in the book working, even when I tried the code from the website (to make sure I didn't fat finger something). I had previously gone through "Lisp for the Web" by Adam Tornhill, where he used Hunchentoot, and the callback handlers seemed similar enough, so I went ahead and converted it.

A few notes:

  1. I used QuickLisp when implementing, then switched to ASDF; either will work, use whatever you're comfortable with. I left the quicklisp code in, commented out, and ASDF seems to "just work" with less fuss, probably because I'm on Debian and installed the cl-hunchentoot package.
  2. There's not much difference in the handlers; I had to redirect the *standard-output* stream as in the original, but because Hunchentoot appears to just grab returned strings and I'm new to Hunchentoot, I used a stringstream and returned a string from that at the end of the handler.
  3. A lot of stuff is just taken care of by Hunchentoot (as any decent server side will do), so you don't need to gin up your own Content-type or HTTP/1.1 header (which was missing in the original "Dice of Doom" code). This includes path and parameter parsing, so chosen becomes a string if it's not nil.
  4. I shamelessly stole some convenience functions for starting and stopping Hunchentoot; link is in the comment above them.
  5. I also took the liberty of changing some identifierssymbols. I believe in code readbility, touch type and use Emacs with dabbrev-expand religiously, so I see no reason to shorten names.

The relevant change is here.

Beware! I am learning, so there may still be issues with this code. I also have to apologize for the sloppiness of the repository history. I wasn't planning on releasing this publicly and it was mainly as a safety net and I was focused on learning the language, not Git. I swear my shared repositories don't usually look this bad!

About

Convert code for "Dice of Doom" from Barski's "Land of Lisp" to use Hunchentoot web server.


Languages

Language:Common Lisp 100.0%