This is giving me a bit of brain thump:
user> (repeatedly 10 #((memoize rand-int) 10))
(7 0 4 8 1 2 2 1 6 9)
user> (repeatedly 10 (partial (memoize rand-int) 10))
(8 8 8 8 8 8 8 8 8 8)
I would like to know if the reason for this is because the function literal (first version) is called/evaluated every time, thus the memoize
is "recreated" (re-memorized) each time, therefore not really having any true meaningful "memorization" at all, while the second one with partial
is actually returning a fixed function that is evaluated just once, where the same value of memoize
is thus used every time (sort of like a closure though I don't think this qualifies as a true "closure")
Am I thinking correctly?