Bill Clementson's Blog

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

August 2005
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 31
Jul  Sep

Some Things Need to be Easy, and Not Just Possible, to Take Advantage of Them

Wednesday, August 17, 2005

Marco Baringer recently made an introductory movie about getting started with UCW. One minor criticism I had of this excellent movie was that it didn't really show off any of the "special characteristics" of a continuation-based web application framework. However, he has just posted on the UCW developer's mailing list a good example of how a continuation-based web application framework makes iterative application refinements easy. I've reproduced his example below (with some minor edits for readability and to convert Italian to English):

"I'm currently working on an app for managing the patients in a hospital. One of the (many, many, many) things it needs to do is generate statistics, one of those statistics requires that you chose a private clinic from a list or type the name into a text box. I initially had these two actions:
(defaction billing-info ((c component) (institution-name string))
  (billing-info c (find-institution institution-name)))

(defaction billing-info ((c component) (institution institution)) ...)

One of the things that kept coming up was that, when using the 'type the name' form, people would misspell the name of the clinic, which would trigger an error page since find-institution returned NIL. so i changed the first method to this:
(defaction billing-info ((c component) (institution-name string))
  (aif (find-institution institution-name)
       (billing-info c it)
       (call 'info-message :message "No clinic with that name.")))
Then we decided it would be nice if the app tried to guess what clinic they wanted, so the action became:
(defaction billing-info ((c component) (institution-name string))
  (aif (find-institution institution-name)
       (billing-info c it)
       (aif (possible-institution institution-name)
	    (billing-info c it)
	    (call 'info-message :message "No clinic with that name."))))
Then we decided that, since some ambiguity can result, it would be nice to show them the list of possible clinics and let them choose:
(defaction billing-info ((c component) (institution-name string))
  (aif (find-institution institution-name)
       (billing-info c it)
       (let ((possibilities (possible-istituti institution-name)))
	 (case (length possibilities)
	   (0 (call 'info-message :message "No institution with that name."))
	   (1 (billing-info c (first possibilities)))
	   (t (billing-info
	       c
	       (call 'option-dialog
		     :message (format nil "No institution with the name ~S"
				      institution-name)
		     :options (mapcar (lambda (institution)
					(cons institution
					      (format nil "Data for the institution ~A."
						      (nome institution))))
				      possibilities))))))))
Notice that in the n possibilities case we still call billing-info but we get the institution from an option-dialog component.

Anyway, my point: Sure I could have done that in any web framework, but I don't think I would have if it hadn't been so easy. Some things need to be easy, and not just possible, in order to take advantage of them."
Good point!

emacs Copyright © 2005 by Bill Clementson