预处理,IFDEF

Che*_* Yu 1 erlang

在调试gen_server模块时,我想记录更多细节状态.

init()->
    put(?COMPLETED_COMMANDS,[]),
-ifdef(DEBUG).
    put(?DETAIL_STATUS,[]),
-endif.
    ok.
Run Code Online (Sandbox Code Playgroud)

编译器给出以下错误.

src/benvolio_command_cache.erl:34: syntax error before: ','
src/benvolio_command_cache.erl:36: syntax error before: '.'
src/benvolio_command_cache.erl:33: variable 'DEBUG' is unbound
src/benvolio_command_cache.erl:33: function ifdef/1 undefined
Run Code Online (Sandbox Code Playgroud)

如何在*.erl文件的功能中添加debuging代码行?

小智 5

宏指令不能在函数内部使用.请参见8.5宏中的流量控制.