[erlang-questions] Self-referencing anonymous functions?

Thomas Allen thomasmallen@REDACTED
Thu Apr 2 20:04:57 CEST 2009


Hi all,

I'm just getting going with Erlang (using Armstrong's book) and I ran
into anonymous functions. I tried translating the shop:cost and
shop:total functions, but I cannot translate the latter because it
refers to itself. How would I rewrite this to not throw errors?

Total = fun ([{What, N}|T]) ->
        Cost(What) * N + Total(T); % Clearly, "Total" won't fly here
    ([]) -> 0
end.

Thanks,
Thomas



More information about the erlang-questions mailing list