lua-users home
lua-l archive

Re: Memoizing Functions - yet another attempt

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Sun, Dec 15, 2013 at 4:37 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

Hmm, maybe I was misunderstood  :>  I was saying that traditionally I've seen people turn to serializing the arg list when allowing for multiple-argument memoized calls.  My approach instead goes for tracking object identity (which I believe to be the more correct approach), by converting each object to a tracked id number.

- if you have multiple return values, pack/unpack them yourself.

Extracting the memoized returns could be argued to be outside the scope of the module, but I wanted to make it "look" as close to the original call and handling of returns as the original function.  I didn't want there to be some extra step to be done by the user :-)  I was aiming for memoized calls to be practically transparent: memoize(f, ...)
 
- functions expensive enough to memoize should not return nil.

I might disagree here... I only started focusing on memoizing functions because I've been attempting to understand lulpeg (lpeg implemented in lua).  I had been looking into memoizing calls made to do pattern matching on large bodies of text.  If the text fails to parse correctly it may return nil, 'error message...'


AltStyle によって変換されたページ (->オリジナル) /