News for hackers. Stuff that matters.
Re:Produce HTML from S-Expressions by ptx on Thursday August 31, 2023 @01:26PM (#37340697)
With this merged attribute syntax, since each key-value combination is a separate symbol and since symbols are interned, doesn't this mean that all the attribute values (and not just the keys) end up interned?

Do Lisp implementations usually garbage-collect interned symbols when they're no longer used?

Re:Produce HTML from S-Expressions by kazinator on Friday September 01, 2023 @12:52AM (#37346922)
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.