[erlang-questions] Random newbie stuff

Brandon Black blblack@REDACTED
Sun Nov 4 14:52:02 CET 2007


On 11/4/07, Dennis Byrne <dbyrne@REDACTED> wrote:
>
>
> Hello Ulf,
>
> If you have a function that is 100% predictable, couldn't there be some
> serious performance gains given that the function is frequently passed the
> same message?  In other words, why put a core to work calculating the result
> you gave last time someone sent you a given message?  It would be better to
> use this function to spawn a process that could use the process dictionary
> as a cache (one that would never expire).



What you're basically asking for there is memoization.  It would be
interesting to have memoization supported at the language level.  The
compiler/interpreter isn't smart enough to know when memoization makes the
most sense (depends on freq/range of inputs, computational complexity of
function), but the programmer probably knows.  You would need a syntax for
specifying function "attributes" to the compiler/interpreter.  Borrowing the
":attrib" syntax from Perl, it would look like:

somecomplexfunc(X) :memoize -> ... complex body ...

I'm guessing that analysis tools could easily throw an error at you if
you've put :memoize on a function which (directly or indirectly by calling
other funcs) makes use of mutable state.

-- Brandon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071104/e75d4235/attachment.htm>


More information about the erlang-questions mailing list