Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weak References in clojure

I would to use something like a weak reference in clojure.

I want to keep track of the return of a particular function. Currently I am doing this using a map which is on the end of a ref. This seems to work quite well. But I would like to keep only those which are not referenced from elsewhere.

In Java I would use a weak reference, or a weak hashtable. I can't find a similar data structure in clojure. It is possible? Or should I just use a WeakHashMap from java? The values in question are clojure records. I guess I can put these into a java collection?

like image 547
Phil Lord Avatar asked Nov 16 '12 19:11

Phil Lord


1 Answers

one of the guiding principals in Clojure is to embrace the host platform where it solves the problem. with that in mind it makes a lot of sense not to wrap the normal Java weak hash map. don't wrap for wrapping sake

like image 165
Arthur Ulfeldt Avatar answered Dec 20 '22 22:12

Arthur Ulfeldt