Fork me on GitHub
#clojure
<
2024-01-28
>
Carsten Behring12:01:57

Can I set var metadata dynamically ? So I can I do the following using intern ?

(def ^{:doc "The clojure doc for row-count"
       :arglists [['dataset-or-ctx]] } row-count (lift tc/row-count))
In which the metadata is a normal map ?

p-himik12:01:41

There's alter-meta!.

Noah Bogart20:01:17

How does structural sharing work with garbage collection? For example, how does the garbage collector know to only collect parts of an object when I dissoc from a map?

Bob B21:01:30

parts of an object are also objects, so my understanding is that GC can collect unreachable nodes. A linked list is maybe the easiest one to visualize... if there's a three-node list, and a new list which conses on to the front, that first node can get GC'ed if the new list goes out of scope/becomes unreachable.

👍 1
andy.fingerhut21:01:04

In general, a full GC implementation starts from "root objects" of your program, and determines all objects reachable through references/pointers in one or more other objects starting at those roots. Any object that cannot be reached is "dead" and subject to collection. Any object that can still be reached through some path from a root is "live".

jaju03:01:49

TBH, list is a simple example. But I suppose persistent datastructures need careful considerations because even if the user-accessible "value" may go unreachable, the update/modify algorithms need to be careful not to keep references to the "discarded" parts.

littleli13:01:21

it is a funny fact that GC is more concerned about live objects than it is about garbage.

andy.fingerhut13:01:39

When you can have cycles in the references/pointers of data structures, as Java allows (as do most general purpose programming languages that have references/pointers), it seems pretty tricky to me to even define what garbage means, except as "not live".

andy.fingerhut13:01:14

If your references/pointers are restricted to be acyclic, you can implement memory management precisely with reference counters to objects, which gives you another precise way to define when something is garbage, but that doesn't work when cycles are allowed.

littleli13:01:21

That's a good observation. The fact that there are like what, 3 other types of references. Like Soft, Weak, Phantom if not more that I'm not aware of 😅

andy.fingerhut13:01:54

Oh, right. I wasn't even factoring those kinds of references in to my comments above. Everything above I was thinking only of "strong" references.