Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

April 2007
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Mar  May

KPAX - A CL Web Application Framework

Sunday, April 8, 2007

I've written in the past about some of the things that Sven Van Caekenberghe has done:

He's written an awful lot of Lisp Software, and I like what he writes. As with Edi Weitz and Marc Battyani (two other independent consultants who do most of their work in CL), his primary CL implementation is LispWorks (which, incidentally, is being offered for the month of April, 2007 for a special, discounted price in celebration of ILC2007) but his software runs on multiple CL implementations. I recently decided to give his KPAX CL web application framework a try and was pretty impressed by what he's done (I've written in the past about other CL web application server options). Since I had just sent Edi some Mac OS X patches for his STARTER-PACK utility, I decided to use STARTER-PACK to download KPAX. As I mentioned in my previous post, Edi provides a mechanism for adding additional libraries; so, I added all of Sven's libraries (with the exception of his CL-SOAP library, which depends on non-released versions of CL-SOAP and S-XML) to the STARTER-PACK using a custom config.lisp file:

Starter Pack with Sven's
Libraries

Then, it was simply a matter of ticking the box for KPAX to install everything I needed.

Sven uses Edi's CL-WHO for HTML generation; so, if you're used to using Edi's tools, you'll find it easy to write HTML code for KPAX. However, Sven also provides a simple form-creation "defwebform" macro that makes it really easy to create data entry forms. For example, this demo page was created by the following code:
(defwebform demo-web-form
  ((:group personal-info 
    :label "Personal Info"
    :members ((fullname :text :label "Fullname")
              (username :text :label "Username" 
                        :options (:size 10)
                        :validator (all required (limited-string 8 4) contains-no-spaces))
              (password :password :label "Password"
                        :options (:size 10)
                        :validator (or optional (limited-string 32)))
              (password2 :password :label "Password"
                         :options (:size 10) :comment "[Confirmation]"
                         :validator (or optional (limited-string 32)))
              (gender :choice
                      :options (:values *genders* :style :buttons)
                      :parser parse-keyword :formatter string-capitalize
                      :validator (or optional (list-element *genders*)))
              (age :text :label "Age" 
                   :options (:size 4)
                   :parser s-utils:parse-integer-safely 
                   :validator (integer-range 0 150))))
   (:group admin-info
    :label "Admin Info"
    :members ((notes :text-area :label "Notes"
                     :options (:cols 40 :rows 10)
                     :validator (or optional (limited-string 256)))
              (enabled-p :choice :label "Enabled"
                         :options (:values :boolean)
                         :parser parse-boolean
                         :validator boolean)))
   (:group preferences
    :label "Preferences"
    :members ((interests :choice
                         :options (:values *interests* :selection :multiple :style :buttons)
                         :parser parse-symbol-kpax-user :formatter string-capitalize
                         :validator (or optional (list-elements *interests*)))
              (language :choice
                        :options (:values *languages* :style :list)
                        :parser parse-symbol-kpax-user :formatter string-capitalize
                        :validator (or optional (list-element *languages*)))
              (music-tastes :choice
                            :options (:values *music-tastes* :style :list :selection :multiple)
                            :parser parse-symbol-kpax-user :formatter string-capitalize
                            :validator (or optional (list-elements *music-tastes*)))))
   (id :hidden))
  (:title "Demo User")
  (:validator validate-demo-web-form)
  (:submit process-demo-web-form))
Sven hasn't provided very much documentation for KPAX; however, a good "getting started" approach would be:
  1. Play around with the live KPAX examples to get a feel for what KPAX can do.
  2. Read the Installing KPAX post that Sven made to the KPAX-devel mailing list. Then, use either the installation instructions he provides or STARTER-PACK (with my custom config.lisp file) to install KPAX.
  3. Read the Running KPAX post that Sven made to the KPAX-devel mailing list and play around with the examples locally. (if you want to use mod_lisp with Apache instead of the built-in HTTP server, read the Installation and Configuration of mod_lisp post too)
  4. Spend some time looking at the example code.
  5. Have a look at Sven's LispWorks HTTP Client/Server and (Re)writing Reddit in Lisp movies (for more tips and inspiration).
  6. Write some sample web apps.
  7. Create the next Viaweb, sell it to Google for millions and become a VC! ;-)
Of course, if you get as far as #7, please remember whose blog posting gave you the idea! ;-)

emacs Copyright © 2007 by Bill Clementson