2007-07-25

#lisp tip of the day

Ever recompiled a function hoping to fix some bug only to find out nothing changed? Perhaps you passed #'some-function around and your live code is still dealing with the old definition? How to tell? Here's an example with SBCL:

* (values (symbol-function (defun foo ()))
          (symbol-function (defun foo ())))
STYLE-WARNING: redefining FOO in DEFUN

#<FUNCTION FOO {11E47CDD}>
#<FUNCTION FOO>
The old version is printed with its object identity (#x11e47cdd in this example), whereas the current global definition is printed without it allowing you to quickly tell which is which. This behaviour is not standard but, for example, OpenMCL provides similar information:
? (values (symbol-function (defun foo ()))
          (symbol-function (defun foo ())))
#<Compiled-function FOO (Non-Global)  #x85AE40E>
#<Compiled-function FOO #x85ADB06>
Your favourite Lisp might also do something along these lines. Great tip by Xof.

0 komentoj:

Kategorioj