Arc Forumnew | comments | leaders | submitlogin
3 points by zhtw 5651 days ago | link | parent

I think that memo should remember the result of the function even if it (the result) was nil. Now it uses hash tables which don't store nils. It would be possible then to be sure that a function won't be called twice it if was wrapped by memo (I used memo for that purpose.)

Here is the discussion: http://arclanguage.com/item?id=8667



4 points by pg 5646 days ago | link

Good idea; fixed:

    (def memo (f)
      (with (cache (table) nilcache (table))
        (fn args 
          (or (cache args)
              (and (no (nilcache args))
                   (aif (apply f args)
                        (= (cache args) it)
                        (do (assert (nilcache args))
                            nil)))))))

-----