Advertisement
lisp123456

Untitled

Dec 3rd, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. ;;;;****************************************************************************
  2.  
  3. ;;; Function Introspection Functions [SBCL specific]
  4.  
  5. (defun function-type (symbol)
  6. "Return the SBCL function type of SYMBOL (:generic, :macro or :function)."
  7. (case (type-of (fdefinition symbol))
  8. (standard-generic-function :generic-function)
  9. (function
  10. (if (macro-p symbol)
  11. :macro
  12. :function))))
  13.  
  14. (defun macro-p (symbol)
  15. "Return t if SYMBOL is a macro and nil otherwise."
  16. (if (macro-function symbol)
  17. t
  18. nil))
  19.  
  20. (defun function-definition-source (symbol &rest method-specializers)
  21. "Return the SBCL definition source of the function associated with SYMBOL."
  22. (case (function-type symbol)
  23. (:generic-function
  24. (if (null method-specializers)
  25. (sb-introspect:find-definition-source (fdefinition symbol))
  26. (let ((method (find-method (fdefinition symbol) nil (mapcar #'find-class method-specializers))))
  27. (sb-introspect:find-definition-source method))))
  28. (:macro (sb-introspect:find-definition-source (macro-function symbol)))
  29. (:function (sb-introspect:find-definition-source (fdefinition symbol)))))
  30.  
  31. (defun function-pathname (symbol &rest method-specializers)
  32. "Return the pathname of the file storing the source of SYMBOL."
  33. (when (null symbol)
  34. (error "Null SYMBOL supplied into FUNCTION-PATHNAME."))
  35. (let ((definition-source (apply #'function-definition-source symbol method-specializers)))
  36. (sb-introspect:definition-source-pathname definition-source)))
  37.  
  38. (defun function-filename (symbol &rest method-specializers)
  39. "Return the file name (without extension) of the file storing the source of SYMBOL as a string."
  40. (when (null symbol)
  41. (error "Null SYMBOL supplied into FUNCTION-FILENAME."))
  42. (let ((definition-source (apply #'function-definition-source symbol method-specializers)))
  43. (pathname-name (sb-introspect:definition-source-pathname definition-source))))
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement