[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Memoizing Functions - yet another attempt
- From: Tim Hill <drtimhill@...>
- Date: Sat, 14 Dec 2013 13:19:44 -0800
On Dec 14, 2013, at 10:04 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>
> That's why memoizing tends to be inflexible, and why the simplest and
> most inflexible solution of all (this version is by Steve Donovan):
>
> function ml.memoize(func)
> return setmetatable({}, {
> __index = function(self, k, ...)
> local v = func(k,...)
> self[k] = v
> return v
> end,
> __call = function(self, k) return self[k] end
> })
> end
>
> is IMHO the only useful way to do it.
>
Translation: Only pure functions should be candidates for memoization.
—Tim