[Bese-devel] ucw coolness story

Marco Baringer mb at bese.it
Wed Aug 17 10:37:45 UTC 2005


hi,

  i'm sure you all know this already, but it really made me smile:

  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 dati-fatturazione ((c component) (istituto-name string))
    (dati-fatturazione c (find-istituto istituto-name)))

  (defaction dati-fatturazione ((c component) (istituto istituto))
    ...)

  (sorry for the weird mix of english and italian. 'istituto' is what
the app calls the private clinics and dati-fatturazione basically
means billing info.)

  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-istituto returned NIL. so i
changed the first method to this:

  (defaction dati-fatturazione ((c component) (istituto-name string))
    (aif (find-istituto istituto-name)
         (dati-fatturazione c it)
         (call 'info-message :message "No clinic with that name.")))

  then we decided i'd be nice if the app tried to guess what clinic
they wanted, so the action became:

  (defaction dati-fatturazione ((c component) (istituto-name string))
    (aif (find-istituto istituto-name)
         (dati-fatturazione c it)
         (aif (possible-istituto istituto-name)
              (dati-fatturazione c it)
              (call 'info-message :message "No clinic with that name."))))

  then we decided that, since some ambiguity can result, it'd be nice
to show them the list of possible clinics and let them chose:

  (defaction dati-fatturazione ((c component) (istituto-name string))
    (aif (find-istituto istituto-name)
         (dati-fatturazione c it)
         (let ((possibilities (possible-istituti istituto-name)))
           (case (length possibilities)
             (0 (call 'info-message :message "Nessun istituto con quel nome."))
             (1 (dati-fatturazione c (first possibilities)))
             (t (dati-fatturazione
                 c
                 (call 'option-dialog
                       :message (format nil "Nessun istituto col nome ~S"
                                            istituto-name)
                       :options (mapcar (lambda (istituto)
                                          (cons istituto
                                                (format nil "Dati per l'istituto ~A."
                                                            (nome istituto))))
                                        possibilities))))))))

  notice that in the n possibilities case we still call
dati-fatturazione but we get the istituto 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.

p.s. - among other things i've been doing some java work and trust me,
nothing hurts as much as xml configuration files and
edit-wait-compile-wait-debug-wait when you've tasted lisp and ucw (and
slime).

p.p.s. - yes, i'm bragging about something i wrote. sue me.

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen



More information about the bese-devel mailing list