News for hackers. Stuff that matters.
Re:Should function arguments be reassignable or mutable? by lozenge on Monday January 01, 2018 @10:02AM (#16046273)
Agreed. Erlang is another language with single assignment, i.e. every variable assignment target must have a new name. It's incredibly easy to see what calculations and conditions affect the final outcome.
Re:Should function arguments be reassignable or mutable? by maxxxxx on Monday January 01, 2018 @11:32AM (#16046658)
How do you do a for loop in Erlang or something that sums up a value ?
Re:Should function arguments be reassignable or mutable? by testvox on Monday January 01, 2018 @12:34PM (#16046984)
You don't usually write for loops in Erlang, as a functional language loops are better expressed as recursive functions.

Here is an example of using a recursive function in Erlang to sum up a factorial.

  fac(1) ->
      1;
  fac(N) ->
      N * fac(N - 1).
Re:Should function arguments be reassignable or mutable? by maxxxxx on Monday January 01, 2018 @01:08PM (#16047149)
Does Erlang handle the stack better? In most languages this would blow up if N got big enough.
Re:Should function arguments be reassignable or mutable? by bearhall on Monday January 01, 2018 @01:38PM (#16047305)
Yes. Erlang has tail recursion which helps prevent that http://learnyousomeerlang.com/recursion
Re:Should function arguments be reassignable or mutable? by dragonwriter on Monday January 01, 2018 @01:43PM (#16047339)
As the article notes, what Erlang has is Last Call Optimization, this is significantly more general than tail recursion optimization.
Re:Should function arguments be reassignable or mutable? by whichdan on Monday January 01, 2018 @04:16PM (#16048096)
In addition to recursion, you can use `foldl` and `foldr` (or similar functional methods)

http://erlang.org/doc/man/lists.html