I just stomped at a begin...end
in Erlang\'s documentation (here), but it doesn\'t give some examples of how it is useful.
Looking here in StackOverflow I f
According to erlang documentation is it block expression that evaluates each expression but returns only the last one.
See this example (not using block expression):
A = 1,
case A + 1 of
3 ->
ok;
_->
nop
end.
% returns ok
Now you can define A within the case argument using block expression:
case begin A = 1, A + 1 end of
3 ->
ok;
_->
nop
end.
%returns ok
That evaluates A = 1, then returns the result of A + 1.
Now we know that this will not work:
case A = 1, A + 1 of
3 ->
ok;
_->
nop
end.
% returns syntax error before: ','