| When f returns smth other than nil then (memo f) works just fine, but if f returns nil then (memo f) calls f again and again when being called itself: arc> (def f ()
(prn "called") 10)
#<procedure: f>
arc> (set g (memo f))
#<procedure>
arc> (g)
called
10
arc> (g)
10
This is ok. Now this: arc> (def f () (prn "called") nil)
#<procedure: f>
arc> (set g (memo f))
#<procedure>
arc> (g)
called
nil
arc> (g)
called
nil
See? f is called twice. I clearly see why from arc.arc, but is it really an intended behavior? |