Suppose I have the module test.erl, and inside it is the macro TOTAL
:
-module(test)
-export([...])
-define(TOTAL,(100))
...
If get_total()
was defined in test.erl, I could call test:get_total().
from the REPL
How do I call ?TOTAL
(the macro) outside of the module test.erl without defining a function?
You could put the -define
in a test.hrl
file, and use -include
to include that in other modules. See the Erlang Preprocessor documentation for more information.
-define(TOTAL, (100)).
-module(test).
-export([...]).
-include("test.hrl").
...
-module(other).
-include("test.hrl").
io:format("TOTAL=~p~n", [?TOTAL]).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With