by Example


Constants in Erlang can be created through the use of macros.

You can define macros for variables or even functions

To expand a macro in your code, use the "?" symbol
followed by the macro name.


-define(N, 123).
-define(M, "what").
-define(SQUARED (X), X*X).

showConstants() ->
    io:format("N = ~p ~n", [?N]),
    io:format("M = ~p ~n", [?M]),
    io:format("~p ~n", [?SQUARED(5)]).
N = 123
M = "what"
Next: Records →