I’ve recently been playing at home & at work with AllegroServe &
Webactions, a web development framework from Franz Inc., one of the leading Common Lisp vendors. Once
you’ve worked your head around it, it’s quite powerful.
I’ve also been learning how to use Lisp macros to reduce my coding
burden. For example, take a look at the following lines:
(def-db-object brewer (thing)
((rating
:type float
:reader rating
:html (html (:princ (make-stars (rating *object*)))))
(beers
:db-kind :join
:db-info (:join-class beer
:home-key name
:foreign-key brewer
:set t)
:accessor beers
:html (let* ((beers (beers *object*))
(webaction (webaction-from-ent ent))
(websession (websession-from-req req))
(beer-path (locate-action-path webaction "beer" websession)))
(html
(:ul
(dolist (beer beers)
;;(error "brewer: ~a; beer: ~a" (name *object*) (name beer))
(html (:li ((:a href (concatenate 'string
beer-path
"?"
(query-to-form-urlencoded `(("brewer" . ,(name *object*))
("name" . ,(name beer))))))
(:princ (name beer) " (" (rating beer)
"-Star "
(style beer)) ")")))))))))
(:base-table "brewers"))
These lines create a class named brewer, which has slots
(members, if you’re familiar with that terminology) named rating
& beers, and which inherits slots from the class named
thing; it also creates nice little HTML-extension
functions to display rating, beers & name, URL and notes inherited
from thing. It also over-rides the default function provided
for rating and displays it as a series of little asterisks instead as a
number, and does the same for beers to instead create a nice little
undelimited list (the :ul bit) with the list items being links to the
beers.
Not too shabby for just a few lines, eh?