Search code examples
erlangexpressionblock

What is begin...end in Erlang used for?


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 found two cases where people would be using begin...end, both in list comprehensions:

But I wonder if there are more of such uses.

Can anyone provide another scenario in which a begin...end is useful in Erlang?

Thanks


Solution

  • Macros, for example:

    -define(M(A, B),
        begin
            C = foo(),
            bar(A, B, C)
        end).