9.4 Macros Overloading
9.4 Macros Overloading
It is possible to overload macros, except for predefined macros. An overloaded macro has more than one definition, each with a different number of arguments.
The feature was added in Erlang 5.7.5/OTP R13B04.
A macro ?Func(Arg1,…,ArgN) with a (possibly empty) list of arguments results in an error message if there is at least one definition of Func with arguments, but none with N arguments.
Assuming these definitions:
-define(F0(), c).
-define(F1(A), A).
-define(C, m:f).
the following does not work:
f0() ->
?F0. % No, an empty list of arguments expected.
f1(A) ->
?F1(A, A). % No, exactly one argument expected.
On the other hand,
f() ->
?C().
is expanded to
f() ->
m:f().
