opening it up with Common Lisp

Favorite weblogs

Lisp Related

Bill Clementson

Finding Lisp

Lemonodor

Lispmeister.com

Planet Lisp

Politics

Orcinus

Talking Points Memo

This Modern World

Working for Change

Other home

Polliblog

Recent Readings

Book review: Darwinia
Reviewed: Friday, August 11, 2006

Summer reading: Spin
Reviewed: Saturday, August 5, 2006

Runner
Reviewed: Tuesday, July 18, 2006

the Omnivoire's Delimma
Reviewed: Wednesday, July 12, 2006

the Golem's Eye
Reviewed: Wednesday, May 31, 2006





tinderbox
 width=

Deprecating
Thursday, May 6, 2004

One thing I've liked in Java is the ability to explicitly mark functions as deprecated. Even though it's not part of the Common Lisp standard, there are lots of ways to accomplish it. One involves writing a compiler macro

(defmacro deprecated (&body body)
  (let ((documentation nil)
        (name nil))
    (when (stringp (first body))
      (setf documentation (first body)
            body (rest body)))
    (setf name (cadar body))
    `(progn
       (define-compiler-macro ,name (&whole form &rest args)
         (declare (ignore args))                          
         (fresh-line *error-output*)
         (write-string ,(format nil "~%; warning ~a has been deprecated.~@[ ~A~]" 
                                name documentation) *error-output*)
         (terpri *error-output*)
         (values form))
       ,@body)))

Making it a compiler macro is cool because it will only bite at compile time and not bother us at run-time. On the down side, Common Lisp implementations are not required to pay any attention to compiler macros (though I think all the major ones do) and we (probably) won't get the warning if we evaluate a form in the Listener.


|

Home | About | Quotes | Recent | Archives

Copyright -- Gary Warren King, 2004 - 2006