[erlang-questions] behavior of funktions

Johannes <>
Mon Jul 23 00:16:12 CEST 2007

i never thought of not-side-effect-free functions in that case ;)
maybe i chosed a bad example.
My question is, if there is a function, wich is called more than one
time with the same arguments, how often is it evaluated(not 'called')?
it's clear, that a its impossible to save all function results the whole
time a programm is running, but how is it for example in a rekursion ??


Christian S schrieb:
> In your case it wont change the result since f is side-effect free
> (ignoring heat dissipation in the computer). Optimizing compilers
> might take advantage of this.
> The semantics is to call f twice, and as you write the way to get
> around it is to
> save the value into a temporary.
> 2007/7/22, Johannes <>:
>> hi, i have a question about the behavior of funktions.
>> if theres a function:
>> f(A,0) ->
>>         1;
>> f(A,B) ->
>>         [f(A,B-1),f(A,B-1)].
>> how often is f(A,B-1) evaluated then ? just one time, and erlang tooks
>> the result everywhere where it fits, like f(A,B) ->
>> TMP=f(A,B-1),[TMP;TMP].
>> or is it evaluated every time again ??

More information about the erlang-questions mailing list