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:

  1. -define(F0(), c).
  2. -define(F1(A), A).
  3. -define(C, m:f).

the following does not work:

  1. f0() ->
  2. ?F0. % No, an empty list of arguments expected.
  4. f1(A) ->
  5. ?F1(A, A). % No, exactly one argument expected.

On the other hand,

  1. f() ->
  2. ?C().

is expanded to

  1. f() ->
  2. m:f().