|
| |||
|
opening it up with Common Lisp |
|||
|
Favorite weblogs Lisp Related Politics Other home Recent Readings
Book review: Darwinia
Summer reading: Spin
Runner
the Omnivoire's Delimma
the Golem's Eye |
|
the Human Condition I like conditions. I like them a lot. I like to use them to describe bad program states instead of strings. (e.g., (defmacro defcondition (name (&rest super-conditions) slot-specs format &body args) (flet ((massage-slot (slot-spec) (cond ((atom slot-spec) `(,slot-spec :initarg ,(read-from-string (format nil ":~a" slot-spec)))) (t slot-spec))) (massage-format-arg (arg) (cond ((atom arg) `(slot-value condition ',arg)) (t arg)))) `(progn (export '(,name)) (define-condition ,name ,super-conditions ,(mapcar #'massage-slot slot-specs) (:report (lambda (condition stream) (format stream ,format ,@(mapcar #'massage-format-arg args)))))))) and this lets us write (define-condition record-number-too-large-error (invalid-record-number-error) ((record-count :initarg :record-count)) (:report (lambda (condition stream) (format stream "Record number ~a is too large for this store. Store size is ~a." (slot-value condition 'record-number) (slot-value condition 'record-count))))) as (defcondition record-number-too-large-error (invalid-record-number-error) (record-count) "Record number ~a is too large for this store. Store size is ~a." record-number record-count) (the record-number slot is inherited). It's not much but its enough to make writing simple condition like this almost as easy as writing an error message as string. Programming environments are (in part) about reducing impedance and about making it easy to do the right thing. | |
|
|
Home | About | Quotes | Recent | Archives Copyright -- Gary Warren King, 2004 - 2006 |