[erlang-questions] Re: Concept of Side-effect

Kaiduan Xie <>
Fri Sep 18 04:34:35 CEST 2009


Thanks Benjamin, but sometimes printing out to the console is really
what you want. Maybe this is not a good example :)

kaiduan

On Thu, Sep 17, 2009 at 10:18 PM, Benjamin Tolputt
<> wrote:
> Kaiduan Xie wrote:
>> Thanks a lot for the great examples. But I can not understand the following one,
>>
>> add(X,Y) ->
>>     X+Y.
>>
>> add_effects(X,Y) ->
>>     io:format("~p~n",[X+Y]).
>>
>> What side-effect add_effects generates? Why we say io:format()
>> generates side-effect?
>>
>
> The side-effect is that there is something printed to the console (or
> stdout). If there were another function (say 'print_screen') that could
> look at the screen, it is possible/likely a call to the add_effects
> function would change the output of the function.
>
> --
> Regards,
>
> Benjamin Tolputt
> Analyst Programmer
>
>


More information about the erlang-questions mailing list