% 매크로 정의
-define(Const, Replacement).
-define(Func(Var1,...,VarN), Replacement).
?Const
?Func(Arg1,...,ArgN)
- 매크로가 여러 모듈에서 사용 가능될 경우, 매크로 정의를 include file에 하는것을 권장한다
- 매크로는 define된 이후에 사용 가능하다.
-define(TIMEOUT, 200).
TIMEOUT == 200.
-define(MACRO1(X, Y), {a, X, b, Y}).
macro2(X,Y) -> {a,X,b,Y}.
?MACRO1(c,d) == macro2(c,d)
compile:file(File, ['P']).
% p 옵션으로 컴파일 하면, p 파일에 전처리 결과가 나타난다.
% https://erlang.org/doc/reference_manual/macros.html
?MODULE
?MODULE_STRING.
?FILE.
?LINE.
?MACHINE.
?FUNCTION_NAME
?FUNCTION_ARITY
?OTP_RELEASE
-define(F0(), c).
-define(F1(A), A).
-define(C, m:f).
?F0. == No, an empty list of arguments expected.
?F1(A, A). == No, exactly one argument expected.
?C(). == m:f().
-undef(Macro).
% Causes the macro to behave as if it had never been defined.
-ifdef(Macro).
%Evaluate the following lines only if Macro is defined.
-ifndef(Macro).
%Evaluate the following lines only if Macro is not defined.
-else.
%Only allowed after an ifdef or ifndef directive. If that condition is false, the lines following else are evaluated instead.
-endif.
%Specifies the end of an ifdef, an ifndef directive, or the end of an if or elif directive.
-if(Condition).
%Evaluates the following lines only if Condition evaluates to true.
-elif(Condition).
%Only allowed after an if or another elif directive. If the preceding if or elif directives do not evaluate to true, and the Condition evaluates to true, the lines following the elif are evaluated instead.
-module(m).
-ifdef(debug).
-define(LOG(X), io:format("{~p,~p}: ~p~n", [?MODULE,?LINE,X])).
-else.
-define(LOG(X), true).
-endif.