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

Benjamin Tolputt <>
Fri Sep 18 04:18:29 CEST 2009


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