Re:Using Recursion in Elixir
by davidstump on Sunday September 06, 2015 @10:33AM
(#10177752)
I believe he is referencing the fact that the map_single function calls itself.
[ Parent
| on HN ]
Gah, indeed it does! I pored over that code to find it and it was right there...
The post still seems to be more about pattern matching than recursion, but at least recursion is in there somewhere!
Actually, you are correct. There is no recursion.
It's perform pattern matching, the functions might have the same name, but it's not recursive, because they are different functions.
Let's pretend we can alias these functions using AS
def map_single({:ok, res}) AS fun1
def map_single({:cols_and_first, cols, first_row}) AS fun2
def map_single({:zipped, list}) AS fun3
def map_single({:error, err}) AS fun4
Notice how it's called.fun1 calls fun2
fun2 calls fun3
fun4
to be recursive, a function must call itself or another function that calls it. neither of this is true. What the article is talking about is pattern matching.