Axet_small Alexey Kuzne... 3 posts

I already finish 3 chapters, but still don’t understand what mean that expression? I know only side effect in C++ or other imperative languages.

 
Generic-user-small Alain O'Dea 18 posts

My understanding (Joe, correct me if I am wrong), is that the term Side effect is used in the book to mean anything that alters state outside of the current function being executed.

All Variables in Erlang are either bound or unbound. Once bound through matching in an expression an Erlang Variable cannot be changed. What appears to be an assignment operator (the ”=” sign) is in actual fact a constraint expression declaring the left and right hand sides of the expression to be equal.

Writing X = 1 followed by X = 2 will fail on X = 2 because X has already been constrained to equal 1 by X = 1. This pattern matching mechanism requires rethinking the design of state and variables in a program. IMHO, the end result is more comprehensible code that is easier to reason about and explain to others.

In Erlang an expression cannot directly modify the state of another function or even other expressions in the same scope. All such modifications are explicitly made through the interpretation of messages or function parameters. By Chapter 3 you have not gotten to see Message Passing or Concurrency. It should hopefully be clearer at that point.

I check this board frequently so please post your questions here. I will do my best to help :)

2 posts, 2 voices