DEV Community

Yufan Lou
Yufan Lou

Posted on

Erlang Punctuations

-module(tut15).

-export([start/0, ping/2, pong/0]).

ping(0, Pong_PID) ->
    Pong_PID ! finished,
    io:format("ping finished~n", []);

ping(N, Pong_PID) ->
    Pong_PID ! {ping, self()},
    receive
        pong ->
            io:format("Ping received pong~n", [])
    end,
    ping(N - 1, Pong_PID).

pong() ->
    receive
        finished ->
            io:format("Pong finished~n", []);
        {ping, Ping_PID} ->
            io:format("Pong received ping~n", []),
            Ping_PID ! pong,
            pong()
    end.

start() ->
    Pong_PID = spawn(tut15, pong, []),
    spawn(tut15, ping, [3, Pong_PID]).

Period .

To signal the end of a function. So each function is a sentence, huh.

Comma ,

To separate expressions in a function. Each expression is a clause, huh.

(Also, of course, to separate parameters and tuple members. But that's common.)

Semicolon ;

To separate pattern match branches. Each pattern match is an independent clause, hmm.

Top comments (0)