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.

README.md 1.6KB

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