[erlang-questions] Re: Concept of Side-effect
Michael Truog
mjtruog@REDACTED
Fri Sep 18 05:15:40 CEST 2009
It is the idea that it is modifying state outside the function. So
printing to the console is a side-effect, it is externalized state.
Kaiduan Xie wrote:
> 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
> <btolputt@REDACTED> 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
>>
>>
>>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
>
More information about the erlang-questions
mailing list