2 ms·
I tried to learn (get to know) Clojure by writing a library for cacheing (memoizing) function calls. I thought it would be a simple exercise, but it turned out
by amelius 7y ago
I tried to learn (get to know) Clojure by writing a library for cacheing (memoizing) function calls. I thought it would be a simple exercise, but it turned out to be not so easy at all, with lots of special cases.
- dmix 7y agoThat seems like an unusual first project. Any reason you chose it? Were you more interested in the language semantics?
- amelius 7y agoIt was because (1) a project I was thinking of would lean heavily on memoized calls, and (2) it would allow me to learn about less basic features like introspection and (3) to quickly see how cleanly the language was designed to not be disappointed later on.
- yayitswei 7y agoYou could check out Clojure's built-in memoize (https://clojuredocs.org/clojure.core/memoize https://clojuredocs.org/clojure.core/memoize)
- harperlee 7y agoCan you give more details? Shouldn’t that be a matter of a macro redifining defn (o create a defn variant a la schema’s defn-spec, or tufte’s defnp ) to capture the call?
- jkxyz 7y agoClojure's implementation of `memoize` is here: https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L6343 https://github.com/clojure/clojure/blob/master/src/clj/cloju... What were the special cases for your use case?