Firstly, obviously yes for un-interned.
TXR Lisp:
This is the TXR Lisp interactive listener of TXR 291.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
I'm confused; is this piano recital Rimsky-Korsakov or Wernicke–Korsakoff?
1> (progn [finalize (gensym "foo-") prinl] nil)
nil
2> (sys:gc)
#:foo-0012
t
3> (sys:gc)
t
We make a gensym whose name starts with foo-. We register a GC finalizer for it which is the prinl function (print, with newline).Then when we manually invoke GC, it gets collected; we see the print.
Internet symbols cannot be collected, normally, because they are always used: they are registered in their package.
TXR Lisp has weak packages, though. A weak package will purge a symbol that is not reachable other than through the package.
1> (make-package "abc" t) ;; t argument here means weak
#<package: abc>
2> (progn [finalize (intern "xyz" *1) prinl] nil)
nil
3> (sys:gc)
abc:xyz
t
4> (package-symbols *1)
nil
5>
Don't know if other Lisp people thunk of this one, but there it is.I don't think I exposed this weak property through the defpackage macro. It's intended for specific scenarios, like reading data in the context of a package.
Do Lisp implementations usually garbage-collect interned symbols when they're no longer used?