Hello, I wrote a persistent LRU cache, but I'm not sure I am satisfied with the interface in particular (and perhaps the implementation). It's at:
http://github.com/scode/plru git://github.com/scode/plru.git (Btw in general I'd appreciate any feedback - especially negative about the implementation. I never felt it was very "nice", but I'm not sure how to make it nicer.) In particular, I find that interacting with the cache becomes very cumbersome and feels non-idiomatic, even though I can't figure out a more idiomatic way to do it. The interface consists of: make-lru -> lru lru-put -> [new-cache] lru-get -> [value new-cache] lru-peak -> [value] lru-contains? -> bool peak, contains? and put feel fine to me because the first two are read-only, and the latter is analogous to conj. "lru-get" is my main sticking point. Due to the nature of an LRU cache, taking an entry from it is not a read-only operation because the point is to evict least recently used entries. So now, instead of: (let [val (lru-get @c key)] ...) One has to write something like: (let [val (dosync (let [[val new-c] (lru-get @c key)] (ref-set c val) val))] ...) One cannot even use 'alter' since there are two interesting things returned, one of which is relevant for the ref, and one of which is relevant for the domain logic. What is a nice clean way to do this idiomatically? One possibility I was thinking of was that, since the expected use case of an LRU cache is so specific, it may be acceptable to have the lru "library" itself provide a side-effect aware interface directly. So, it might provide ! versions of its public interface which expects to receive a ref, such that you can now do: (let [val (dosync (lru-get! c key))] ...) Instead of every potential caller having to do mostly the same thing anyway. What do you think? -- / Peter Schuller -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en