preprocessor - Erlang macros with different arity -
for logging wanted ability macro out statements @ compile time, -define rescue!
for compiler flags i'm compiling erlc -dfoo, there way -ifdef determine difference between foo = ok, foo/0, , foo/1?
-module(foo). -define(foo, ok). -define(foo(x), io:format("~p~n", [x])). -export([test_x/1]). %% want true iff foo = ok, not if ?foo/1 exists -ifdef(foo). test_x(x) -> ?foo(":) " ++ x). -else. test_x(x) -> ?foo(":( " ++ x). -endif.
i had better write fuller reply.
no, there no way test actual macro definition, can test if macro name has been defined. , can test on macro name, not on alternative macro definitions different arities. relic past, before r13b, when have 1 macro definition per name. new 1 more closely mimics functions in module.
the "standard" way of doing use flag macro determine set of macros/functions use. example:
-ifdef(debug). -define(debug_print(x), <... long here ...>). foo(x) -> <... debuggy stuff here ...>. -else -define(debug_print(x), ok). foo(x) -> <... normal stuff here ...>. -endif.
Comments
Post a Comment