This is probably easy for someone with experience in Erlang but I have none. Im trying to make a fibonacci tree of processes. It shall then accept a message where i can calculate the sum of all nodes under the one im passing it to.
create_fibtree(N) when N > 1 ->
Child1 = spawn(fun() -> create_fibtree(N-1) end),
Child2 = spawn(fun() -> create_fibtree(N-2) end),
receive
Sum ->
Child1 ! sum + 1,
Child2 ! sum + 1,
io:format ("sum is ~p.~n", [Sum])
end;
create_fibtree(N) when N =< 1 ->
ok.
When i run this:
c(fib_tree2).
{ok,fib_tree2}
2> fib_tree2:create_fibtree(10).
the Erlang console hangs. Cant figure out why but its something with the receive clause right?
And yes this is an homework, my teacher isn't there this week, that's why im looking for stand ins on the internet.