A reader-macro way to create non-destructive nicknames within portable Common Lisp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

package.lisp 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. ;;;; package.lisp
  2. (defpackage #:pseudonyms
  3. (:use #:cl #:trivial-garbage)
  4. (:export :*pseudonym-table*
  5. :defpseudonym
  6. :pmakunbound
  7. :print-pseudonyms
  8. :pseudonym-reader)
  9. (:documentation
  10. "============================ PSEUDONYMS ===================================
  11. I found that Lisp nicknames, as defined in CLHS, have a few problems that I
  12. will count here.
  13. 1) They are not changeable without internal side-effects. RENAME-PACKAGE
  14. is destructive, as it kills off any previous names the package.
  15. 2) They collide. Nickname GL is used by at least three different Lisp
  16. packages.
  17. The solution I provide here is a different approach to nicknames that does
  18. not use any of the original nickname code, as defined in CLHS.
  19. Pseudonyms, in opposition to nicknames, can be defined by the user inside
  20. one's code, like this:
  21. > (defpseudonym \"longpackagename\" \"lpn\")
  22. And removed like this:
  23. > (pmakunbound \"lpn\") ;; OR (pmakunbound \"longpackagename\")
  24. From within the code, one can refer to a pseudonymized package this way:
  25. > $lpn:something
  26. A reader macro will automatically translate it to its normal version of
  27. longpackagename:something. This is usable both within the REPL and within
  28. usual code.
  29. All pseudonyms are local to the current package: for instance, pseudonyms
  30. defined within CL-USER are not usable anywhere outside the CL-USER package.
  31. An utility function print-pseudonyms will print all pseudonyms for a given
  32. package. If not supplied a package name as an argument, it will print all
  33. pseudonyms for current package (as shown by the *package* global variable).
  34. "))