If you use hash-maps, or a struct-map as the basis of your individual, you can just make a key 'fitness', and store the once-calculated fitness in there.
I'm not sure how, but it might be possible that at the creation of your animals, you assign the key 'fitness' a basic function that upon being accessed replaces itself with its outcome. I would be interested in seeing that coded. It would be a very neat way to do what you want. proof of concept, which is not going to win a beaty contest. user=> (def myhost (hash-map :c 15 :b 3 :a (fn [hostname] (assoc hostname :a (* (hostname :b) (hostname :c)))))) #'user/myhost user=> myhost {:a #<user$fn__35 user$fn_...@d85cc>, :b 3, :c 15} user=> (def myhost ((myhost :a) myhost)) #'user/myhost user=> myhost {:a 45, :b 3, :c 15} user=> On Mar 4, 6:27 pm, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > Am 04.03.2009 um 18:21 schrieb Dan: > > > How can I have my fitness computation be triggered on first access > > and reused afterward? > > Maybe you can use a Delay. > > {:fitness (delay (compute-my-fitness))} > > And when you access the value use force. > > (-> my-thing :fitness force) > > The first time it is accessed, the value is calculated. > Afterwards the cached value is returned. If you don't > use the value of interim stages, it is not calculated. > > Sincerely > Meikel > > <commercial> > If you use maps as above I also have a lazy-map > package, which evaluates the value of key only > in case it is really accessed. > > http://bitbucket.org/kotarak/lazymap > </commercial> > > smime.p7s > 5KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---