Erlang Mailing Lists

Author Message

<  Erlang questions mailing list  ~  gen_server:handle_call & -ifdef

Gerald.Biederbeck at eed.
Posted: Thu Nov 02, 2000 4:37 pm Reply with quote
Guest
Hi,

I wrote a gen_server and tried to compile it:
the source code is something like this:

> -ifdef(erlang_debug).
>
> handle_call(aaa, From, State) ->
> Reply = aaa,
> {reply, Reply, State};
>
> -endif.
>
> handle_call(Request, From, State) ->
> Reply = ok,
> {reply, Reply, State}.

The error I got was:

> ./ifdef.erl:91: unterminated '-ifdef'

I assume that it must have something to do
with "not ending with a dot" before '-endif.',
because the following works:

> -ifdef(erlang_debug).
>
> handle_call(aaa, From, State) ->
> Reply = aaa,
> {reply, Reply, State};
>
> handle_call(Request, From, State) ->
> Reply = ok,
> {reply, Reply, State}.
>
> -else.
>
> handle_call(Request, From, State) ->
> Reply = ok,
> {reply, Reply, State}.
>
> -endif.


Is there any documentation for this '-ifdef().'???
Is the second way as I am supposed to do it?

Any help and comments are welcome!

Regards
/Gerry


Post generated using Mail2Forum (http://m2f.sourceforge.net)
raimo at erix.ericsson.se
Posted: Fri Nov 03, 2000 9:26 am Reply with quote
Guest
Hi Gerry,

there is some documentation in "Erlang Extensions since 4.4", link from
http://erlang.org/doc/r7b/doc/index.html. This, unfortunately, says
nothing about the behagiour You encountered.

There is also the Erlang specification, that slowly is getting out of
date but still is the best there is. It is found at
http://erlang.org/download/erl_spec47.ps.gz, gzipped Postscript, sorry.
There the behaviour is stated, perhaps not too clearly, in sections 7.1
and 7.4.

In short, the preprocessor reads a sequence of TokenSequences. A
TokenSequence is terminated by a full stop ("."), so an "-ifdef()."
directive is a TokenSequence, and an "-endif." too, and what comes
before, in between and after must also be terminated with a full stop.

Too bad.

One standard trick is to conditionally define a debug printout macro
like this:

-ifdef(erlang_debug).
-define(dbg_out(Term), io:format("~p~n", [Term])).
-else.
-define(dbg_out(Term), ok).
-endif.

, but that won't help You, but a similar trick might:

-ifdef(erlang_debug).
-define(handle_call_aaa,
handle_call(aaa, From, State) ->
Reply = aaa,
{reply, Reply, State}Wink.
-else.
-define(handle_call_aaa, ).
-endif.
.
.
?handle_call_aaa
handle_call(Request, From, State) ->
Reply = ok,
{reply, Reply, State}.

, or this more generic macro hackery:

-ifdef(erlang_debug).
-define(dbg(X), X).
-else.
-define(dbg(X), ).
-endif.
.
.
?dbg(handle_call(aaa, From, State) ->
begin
Reply = aaa,
{reply, Reply, State}
end;)
handle_call(Request, From, State) ->
Reply = ok,
{reply, Reply, State}.

this is on thin ice, however. E.g You need the begin .. end construct to
keep together the argument to the dbg macro, and You cannot have more
that one guard since then You need commas, which split the argument to
the dbg macro into two. That can be solved with a dbg macro with more
arguments, for the guards, and now it gets really ugly.

Good luck, anyway.

/ Raimo Niskanen, Erlang/OTP



Gerald Biederbeck wrote:
>
> Hi,
>
> I wrote a gen_server and tried to compile it:
> the source code is something like this:
>
> > -ifdef(erlang_debug).
> >
> > handle_call(aaa, From, State) ->
> > Reply = aaa,
> > {reply, Reply, State};
> >
> > -endif.
> >
> > handle_call(Request, From, State) ->
> > Reply = ok,
> > {reply, Reply, State}.
>
> The error I got was:
>
> > ./ifdef.erl:91: unterminated '-ifdef'
>
> I assume that it must have something to do
> with "not ending with a dot" before '-endif.',
> because the following works:
>
> > -ifdef(erlang_debug).
> >
> > handle_call(aaa, From, State) ->
> > Reply = aaa,
> > {reply, Reply, State};
> >
> > handle_call(Request, From, State) ->
> > Reply = ok,
> > {reply, Reply, State}.
> >
> > -else.
> >
> > handle_call(Request, From, State) ->
> > Reply = ok,
> > {reply, Reply, State}.
> >
> > -endif.
>
> Is there any documentation for this '-ifdef().'???
> Is the second way as I am supposed to do it?
>
> Any help and comments are welcome!
>
> Regards
> /Gerry


Post generated using Mail2Forum (http://m2f.sourceforge.net)
yeti
Posted: Sat Sep 01, 2012 5:59 am Reply with quote
User Joined: 01 Sep 2012 Posts: 17 Location: fgf
cheap designer *beep* are the most suitable accessories for women who are fond of attending parties.There are different style in our cheap *beep* shop.cheap purses are a kind of practical products and are full of vitality.If you can choose cheap designer bags right now, we can supply all kinds of cheap bags from stock.
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum