Erlang understand recursion -
i have problems understanding recursion , hoping help. have 2 examples answers can't understand how outcomme calculated. f1(x, [x | ys]) -> [x] ++ f1(x, ys); f1(x, [y| xs]) -> tl(f1(y, xs)) ++ [x]; f1(x, []) -> [x,x]. if run code with: f1(2, [1,1,1,6]). -> [1,6,1,2] another example: f1(c, [f,b,d,d,a]) -> [b,f,c] can please explain me how function calculates? :) another recursion function can't grasp one: f2([x|xs]) when x > 2 -> [x|f2(xs)]; f2([x|xs]) -> [y|ys] = f2(xs), [y,x+y|ys]; f2([]) -> [1]. example: f2([3,1,2]). -> [3,1,2,3]. how that? thanks in advance :) these examples make use of erlang's pattern matching. the first clause of first example match if first element of list same first argument f1(x, [x | ys]) -> [x] ++ f1(x, ys); the second clause match other cases list not empty f1(x, [y| xs]) -> tl(f1(y, xs)) ++ [x]; and last clause matches empty list. f1(x, []) -> [x,x]. when ev...