Skip to content

Instantly share code, notes, and snippets.

@Jach
Created August 11, 2018 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jach/b4493217ae2850db9ac71d538fcae48a to your computer and use it in GitHub Desktop.
Save Jach/b4493217ae2850db9ac71d538fcae48a to your computer and use it in GitHub Desktop.
Track undefined function warnings in SBCL
; put this in my .sbclrc file.
; useful idea I had, rebind defun to keep track
; of functions that have been referenced but not yet
; defined. Loosely inspired by Utopian.
(setf (macro-function 'cl-defun) (macro-function 'defun))
(defparameter *undefined-functions* nil)
(handler-bind
((warning
(lambda (w)
(declare (ignorable w))
(invoke-restart 'muffle-warning)))
(sb-ext:symbol-package-locked-error
(lambda (e)
(declare (ignorable e))
(invoke-restart 'continue))))
(defmacro defun (name args &body body)
`(handler-bind
((sb-int:simple-style-warning
(lambda (w)
(let ((c (simple-condition-format-control w))
(a (simple-condition-format-arguments w)))
(when (and (equal c "undefined ~(~A~): ~S")
(eql (length a) 2)
(eql (first a) :function))
(setf *undefined-functions*
(union *undefined-functions* (cdr a))))))))
(eval '(cl-defun ,name ,args ,@body))
(setf *undefined-functions*
(set-difference *undefined-functions* '(,name)))
(if (plusp (length *undefined-functions*))
(format t
"; REMINDER: you still have undefined functions ~S"
*undefined-functions*)))))
(defun typo (fn)
"Remove undef fn reminder manually, e.g. due to typos."
(setf *undefined-functions*
(set-difference *undefined-functions* (list fn))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment