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:
- 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. - 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. - 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
orHTTP/1.1
header (which was missing in the original "Dice of Doom" code). This includes path and parameter parsing, sochosen
becomes a string if it's notnil
. - I shamelessly stole some convenience functions for starting and stopping Hunchentoot; link is in the comment above them.
- I also took the liberty of changing some
identifierssymbols. I believe in code readbility, touch type and use Emacs withdabbrev-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!