[erlang-questions] why isn't scope in "begin end" block？
Sat Oct 10 15:22:33 CEST 2015
>>>>> "dg" == Dao Gui <> writes:
dg> The var A is in begin end scope, but it can visited by other
dg> scope. Why isn't erlang support this?
Because the documentation says so:
The scope for a variable is its function clause. Variables bound in
a branch of an if, case, or receive expression must be bound in all
branches to have a value outside the expression. Otherwise they are
regarded as 'unsafe' outside the expression.
dg> -define(OUTPUT_3(A), begin [_,_,B|_]=A, io:format("~p~n", [B]) end).
-define(OUTPUT_3(A), io:format("~p~n", lists:nth(3, A))).
More information about the erlang-questions