I have a map like this:
(def a {:a 1, :b 2})
: I want to reload the map so that some keywords perform functions so that:
(c: a)
It can perform a function. Is it possible?
Update:
I understand that I can do something like:
(def a {:a (fn[] 1) :b (fn[] 2) :c (fn[] x)})
: a:
((c: a))
: but then I have to convert every existing map entry that I have into a function.
I want the function to be "reevaluated" every time. For example, when I do:
(def ab{:a 1 :b 2 :c ( #(.nextInt (java.util.Random.) 1000))}) (str (:c ab) " " (:c ab) " " (:c ab))
I get:
61 61 61
Instead of three different numbers
Update 2
I thought about the answer that gave me, and realized that he was right, I should only use immutable structures. The final solution I came up with was to have an enrichment function that creates dynamic properties on demand.
(def a {:a 1, :b 2})
: I want to reload the map so that some keywords perform functions so that:
(str (:c (enrich ab)) " " (:c (enrich ab)) " " (:c (enrich ab)))
will produce different numbers every time like this:
58 639 710
source share