Re: Soliciting criticism of memoize function
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Soliciting criticism of memoize function
- From: Norman Ramsey <nr@...>
- Date: 2008年5月17日 13:41:38 -0400
> I don't see why the 'update' closure is needed. Wouldn't it be more
> straightforward to just say:
>
> ... v, extra = f(x); assert(extra == nil) ...
I'm more paranoid than that. f might return multiple arguments, some
of which are nil. You'll note that even the standard library
functions do this, although not with nil in the second position.
> Also, it's easy to allow f to return any number of values ...
>
> ... v = { f(x) } -- save all return values
> ...
> return unpack(cache[x])
Yes, this is probably worth doing, although I'm a little reluctant to
pay the overhead of 'unpack' on the fast path when *none* of the
applications I have in mind need it.
Norman