[erlang-questions] one-time evaluated functions
Mon Oct 30 18:05:59 CET 2017
1. (Boring) Have a persistent store somewhere, and have the function check
if the value is stored there or not. If not, compute it and store. An ETS
table would work fine, but you need to ensure it's lifetime matches your
requirements. A plain file containing term_to_binary/1 of the value should
also work. Or use a DB.
2. (More fun) Place the function in a module M. Initial version computes
the value and generates a new version of the module where the function now
just returns that constant value. There will probably be some restrictions
on what kinds of values you can return this way, i.e. I wouldn't expect a
function value with closed over free variables to work, but anything you
could include in a pattern match should work.
On Mon, Oct 30, 2017 at 4:41 PM, Jarosław Preś <jaroslaw.p.75@REDACTED>
> Is it possible to make an erlang function be evaluated only once at first
> call and then return this value each time?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions