[erlang-questions] question: macro definition

Ahmed Ali <>
Tue Jan 15 19:40:23 CET 2008


Thanks Primanathan,

This is a smart solution. I wonder how come I didn't think of it. I
thought I know how to write functional program :)

Best regards,

Ahmed Al-Issaei

On Jan 15, 2008 7:23 PM, Primanathan Reddy [ MTN - Innovation Centre ]
<> wrote:
>
>
>
>
> Hi
>
>
>
> If you really want to use the same MACRO name you can try this!
>
>
>
> -define( LOG( ARGS ), fun( [X] )   -> io:format( "~w~n", [X] );
>
>    ([X,D])   ->  io:format( "~w~w~n", [X,D] );
>
>    (_) -> void end ).
>
>
>
>
>
>
>
> Then you can use ?LOG( [TERM1] )  and ?LOG( [TERM1, TERM2] ).
>
>
>
>
>
>
>
>  ________________________________
>
>
> From: 
> [mailto:] On Behalf Of Ahmed Ali
>  Sent: Tuesday, 15 January 2008 03:32 PM
>  To: Erlang
>  Subject: [erlang-questions] question: macro definition
>
>
>
>
>
> Hi,
>
>  I have a question about macro definitions in Erlang.
>
>  When I write the following in my .hrl file:
>
>  <code>
>  [line 10] -define(LOG(X), io:format("~w~n",[X])).
>  [line 11] -define(LOG(X,D), io:format("~w~n",[X,D])).
>  </code>
>
>  I get the following compile error:
>
>  ./../include/file.hrl:11: redefining macro ''LOG''
>
>  Can someone explain to me what "redefining" means here? Does that mean if I
> cannot define a macro with the same name even though they have different
> arity?
>
>  Best regards,
>
>  Ahmed Al-Issaei NOTE: This e-mail message is subject to the MTN Group
> disclaimer see http://www.mtn.co.za/default.aspx?pid=34411



More information about the erlang-questions mailing list