loading...

Erlang Punctuations

louy2 profile image Yufan Lou ・1 min read
-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.

Posted on by:

louy2 profile

Yufan Lou

@louy2

Learning Rust and Haskell, tired of JavaScript. Thinks Ruby is awesome except that it is not cross-platform enough. 日本語 / 中文 OK. He/him.

Discussion

markdown guide