开发者

Erlang: How to use a -define macro outside of a module?

开发者 https://www.devze.com 2023-01-18 12:27 出处:网络
Suppose I have the module test.erl, and inside it is the macro TOTAL: -module(test) -export([...]) -define(TOTAL,(100))

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 开发者_如何学Pythoncould 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.

test.hrl

-define(TOTAL, (100)).

test.erl

-module(test).
-export([...]).

-include("test.hrl").

...

other.erl

-module(other).

-include("test.hrl").

io:format("TOTAL=~p~n", [?TOTAL]).
0

精彩评论

暂无评论...
验证码 换一张
取 消