Klimi's new dotfiles with stow.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

63 rader
2.6 KiB

4 år sedan
  1. ;;; swank-util.lisp --- stuff of questionable utility
  2. ;;
  3. ;; License: public domain
  4. (in-package :swank)
  5. (defmacro do-symbols* ((var &optional (package '*package*) result-form)
  6. &body body)
  7. "Just like do-symbols, but makes sure a symbol is visited only once."
  8. (let ((seen-ht (gensym "SEEN-HT")))
  9. `(let ((,seen-ht (make-hash-table :test #'eq)))
  10. (do-symbols (,var ,package ,result-form)
  11. (unless (gethash ,var ,seen-ht)
  12. (setf (gethash ,var ,seen-ht) t)
  13. (tagbody ,@body))))))
  14. (defun classify-symbol (symbol)
  15. "Returns a list of classifiers that classify SYMBOL according to its
  16. underneath objects (e.g. :BOUNDP if SYMBOL constitutes a special
  17. variable.) The list may contain the following classification
  18. keywords: :BOUNDP, :FBOUNDP, :CONSTANT, :GENERIC-FUNCTION,
  19. :TYPESPEC, :CLASS, :MACRO, :SPECIAL-OPERATOR, and/or :PACKAGE"
  20. (check-type symbol symbol)
  21. (flet ((type-specifier-p (s)
  22. (or (documentation s 'type)
  23. (not (eq (type-specifier-arglist s) :not-available)))))
  24. (let (result)
  25. (when (boundp symbol) (push (if (constantp symbol)
  26. :constant :boundp) result))
  27. (when (fboundp symbol) (push :fboundp result))
  28. (when (type-specifier-p symbol) (push :typespec result))
  29. (when (find-class symbol nil) (push :class result))
  30. (when (macro-function symbol) (push :macro result))
  31. (when (special-operator-p symbol) (push :special-operator result))
  32. (when (find-package symbol) (push :package result))
  33. (when (and (fboundp symbol)
  34. (typep (ignore-errors (fdefinition symbol))
  35. 'generic-function))
  36. (push :generic-function result))
  37. result)))
  38. (defun symbol-classification-string (symbol)
  39. "Return a string in the form -f-c---- where each letter stands for
  40. boundp fboundp generic-function class macro special-operator package"
  41. (let ((letters "bfgctmsp")
  42. (result (copy-seq "--------")))
  43. (flet ((flip (letter)
  44. (setf (char result (position letter letters))
  45. letter)))
  46. (when (boundp symbol) (flip #\b))
  47. (when (fboundp symbol)
  48. (flip #\f)
  49. (when (typep (ignore-errors (fdefinition symbol))
  50. 'generic-function)
  51. (flip #\g)))
  52. (when (type-specifier-p symbol) (flip #\t))
  53. (when (find-class symbol nil) (flip #\c) )
  54. (when (macro-function symbol) (flip #\m))
  55. (when (special-operator-p symbol) (flip #\s))
  56. (when (find-package symbol) (flip #\p))
  57. result)))
  58. (provide :swank-util)