Context
Consider the following code snippet
(defprotocol ICat "Foo" (meow [cat])) (defrecord Cat [ab] "Cat" ICat (meow [cat] (some-expensive-operation ab)))
Question
Is there a way I can put somewhere there?
I would prefer that (some expensive operation ab) be evaluated exactly once, at runtime
(->Cat ab)
so that during (meow cat), he simply returns the previously cached value, and does not recount it on the fly. For example:
[1] (let [x (->Cat ab)] [2] (meow x) [3] (meow x) [4] (meow x))
I want (some expensive operation) to be evaluated exactly once in [1], then for [2], [3], [4] it just returns the old value.
user1311390
source share