3 ms·
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 calculat
by lozenge 9y ago
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.
- maxxxxx 9y agoHow do you do a for loop in Erlang or something that sums up a value ?
- testvox 9y agoYou 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).
- maxxxxx 9y agoDoes Erlang handle the stack better? In most languages this would blow up if N got big enough.
- bearhall 9y agoYes. Erlang has tail recursion which helps prevent that http://learnyousomeerlang.com/recursion http://learnyousomeerlang.com/recursion
- dragonwriter 9y agoAs the article notes, what Erlang has is Last Call Optimization, this is significantly more general than tail recursion optimization.
- deleted 9y ago[deleted]
- whichdan 9y agoIn addition to recursion, you can use `foldl` and `foldr` (or similar functional methods) http://erlang.org/doc/man/lists.html http://erlang.org/doc/man/lists.html