Search code examples
syntaxerlangpunctuation

In Erlang, when do I use ; or , or .?


I have been trying to learn Erlang and have been running into some problems with ending lines in functions and case statements.

When do I use a semicolon (;), comma (,), or period inside my functions or case statements?


Solution

  • Comma at the end of a line of normal code.
    Semicolon at the end of case statement, or if statement, etc. The last case or if statement doesn't have anything at the end. A period at the end of a function.

    example (sorry for the random variable names, clearly this doesn't do anything, but illustrates a point):

    case Something of 
        ok ->
            R = 1,     %% comma, end of a line inside a case 
            T = 2;     %% semi colon, end of a case, but not the end of the last
        error ->
            P = 1,     %% comma, end of a line inside a case
            M = 2      %% nothing, end of the last case
    end.               %% period, assuming this is the end of the function, comma if not the end of the function