[erlang-questions] Random newbie stuff
Sun Nov 4 16:51:14 CET 2007
2007/11/4, Dennis Byrne <dbyrne@REDACTED>:
> 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).
> Unless ... are gets and puts to the dictionary thread safe?
Hmm, these are two different questions.
The immutability part means that stuff like this is not possible in Erlang:
void foo( int &i )
int bar = 5; // bar == 5
foo( bar ); // bar == 6
foo( bar ); // bar == 7
(from http://developer.kde.org/~wheeler/cpp-pitfalls.html, one of many web
pages listing C++ pitfalls).
The fact that a function will return the same value every time it is called
with the same input, doesn't mean to imply that you have to call it every
time you have a certain set of values. (-:
It's not a matter of efficiency. It's rather a sanity thing. When you debug
functional code, it takes only moments to determine that a function depends
only on its input parameters. Once you've done that, you can figure out what
it does, and rest assured that this will always hold.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions