[erlang-questions] memoization (was: Re: [Fwd: Re: Functional Programming])
Colin Meyer
cmeyer@REDACTED
Fri Aug 31 18:50:05 CEST 2007
Hi,
Thanks for your reply. I hadn't gotten to learning about ETS yet. I
guess that this is fairly similar to my idea of caching results in the
process dictionary.
Is it a correct understanding that caching is not practical with "pure"
Erlang data structures?
Thanks,
-Colin.
On Fri, Aug 31, 2007 at 11:24:52AM -0500, Matthew O'Gorman wrote:
> i have this
> memo.erl:
> -module (memo).
> -export ([y/1, memoize/1, fib/1]).
>
> y (F) ->
> F (fun (X) -> (y (F)) (X) end).
>
> memoize (Tab, F) ->
> fun (B) ->
> fun (C) ->
> case ets:lookup (Tab, C) of
> [] ->
> R = (F (B)) (C),
> ets:insert (Tab, {C, R }),
> R;
> [{C, R}] ->
> R
> end
> end
> end.
[...]
More information about the erlang-questions
mailing list