exclude function calls

Thomas Lindgren <>
Sat Mar 25 20:57:36 CET 2006



--- Yani Dzhurov <> wrote:

> Hi guys, 
> 
>  
> 
> Is it possible to exclude some particular function
> calls in function
> definition while compilation.

How about this:

Define this macro somewhere (actually, conditional
compilation might be cleaner here :-):

-define(maybe(Expr), Expr).
%%-define(maybe(Expr), ok).

Then wrap the calls that you want to exclude:

f() ->
  foo(),
  ?maybe(bar()),
  baz().

The above ?maybe can still yield compilation errors if
you export variables from it. (Consider the case when
?maybe(E) expands to 'ok'.) You could also define it
this way:

-define(maybe(Expr), (fun() -> Expr end)() ).

This prevents locally bound variables from escaping
the ?maybe, and can in principle be compiled as
efficiently as just executing Expr. I'm not sure if
the compiler does that optimization, however.

Best,
Thomas


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the erlang-questions mailing list