[erlang-questions] why isn't scope in "begin end" block?

Kevin Montuori montuori@REDACTED
Sat Oct 10 15:22:33 CEST 2015


>>>>> "dg" == Dao Gui <guidao1013@REDACTED> 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.

http://www.erlang.org/doc/reference_manual/expressions.html#id79254


    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))).



k.

-- 
  Kevin Montuori
  montuori@REDACTED



More information about the erlang-questions mailing list