Matt Williamson | 18 Aug 17:32
Gravatar

Edoc optional function parameters

Hello,

In the docs for gen_server, there for example is call/2,3, two signatures for the same base function. How do I use edoc to do something similar? Basically I want one argument to be optional without writing a <at> spec for each one. Here's what I have now:

%%===================================================================
%% API
%%===================================================================
%%-------------------------------------------------------------------
%% <at> spec put(Node, Key, Value) -> Result
%%     Result = {ok, inserted, Key} | {error, notinserted}
%%     Key = term()
%%     Value = term()
%%     Node = node()
%% <at> doc Inserts a Key, Value pair into the server.
%%-------------------------------------------------------------------
put(Key, Value) ->
    put(node(), Key, Value).

put(Node, Key, Value) ->
    gen_server:call({simpledb_svr, Node}, {insert, Key, Value}).
<div><div dir="ltr">Hello,<br><br>In the docs for gen_server, there for example is call/2,3, two signatures for the same base function. How do I use edoc to do something similar? Basically I want one argument to be optional without writing a  <at> spec for each one. Here's what I have now:<br><br>%%===================================================================<br>%% API<br>%%===================================================================<br>%%-------------------------------------------------------------------<br>
%%  <at> spec put(Node, Key, Value) -&gt; Result<br>%%&nbsp;&nbsp;&nbsp;&nbsp; Result = {ok, inserted, Key} | {error, notinserted}<br>%%&nbsp;&nbsp;&nbsp;&nbsp; Key = term()<br>%%&nbsp;&nbsp;&nbsp;&nbsp; Value = term()<br>%%&nbsp;&nbsp;&nbsp;&nbsp; Node = node()<br>%%  <at> doc Inserts a Key, Value pair into the server.<br>
%%-------------------------------------------------------------------<br>put(Key, Value) -&gt;<br>&nbsp;&nbsp;&nbsp; put(node(), Key, Value).<br><br>put(Node, Key, Value) -&gt;<br>&nbsp;&nbsp;&nbsp; gen_server:call({simpledb_svr, Node}, {insert, Key, Value}).<br>
</div></div>
Richard Carlsson | 18 Aug 19:18
Favicon

Re: Edoc optional function parameters

Matt Williamson wrote:
> Hello,
> 
> In the docs for gen_server, there for example is call/2,3, two
> signatures for the same base function. How do I use edoc to do something
> similar? Basically I want one argument to be optional without writing a
> @spec for each one. Here's what I have now:
> 
> %%===================================================================
> %% API
> %%===================================================================
> %%-------------------------------------------------------------------
> %% @spec put(Node, Key, Value) -> Result
> %%     Result = {ok, inserted, Key} | {error, notinserted}
> %%     Key = term()
> %%     Value = term()
> %%     Node = node()
> %% @doc Inserts a Key, Value pair into the server.
> %%-------------------------------------------------------------------
> put(Key, Value) ->
>     put(node(), Key, Value).
> 
> put(Node, Key, Value) ->
>     gen_server:call({simpledb_svr, Node}, {insert, Key, Value}).

You currently need to provide a spec for both, but for put/2, you
can write "@equiv put(node(), Key, Value)" instead of the @doc.

    /Richard
Matt Williamson | 18 Aug 20:06
Gravatar

Re: Edoc optional function parameters

Thank you. That's good enough.

On Mon, Aug 18, 2008 at 1:18 PM, Richard Carlsson <richardc <at> it.uu.se> wrote:
Matt Williamson wrote:
> Hello,
>
> In the docs for gen_server, there for example is call/2,3, two
> signatures for the same base function. How do I use edoc to do something
> similar? Basically I want one argument to be optional without writing a
> <at> spec for each one. Here's what I have now:
>
> %%===================================================================
> %% API
> %%===================================================================
> %%-------------------------------------------------------------------
> %% <at> spec put(Node, Key, Value) -> Result
> %%     Result = {ok, inserted, Key} | {error, notinserted}
> %%     Key = term()
> %%     Value = term()
> %%     Node = node()
> %% <at> doc Inserts a Key, Value pair into the server.
> %%-------------------------------------------------------------------
> put(Key, Value) ->
>     put(node(), Key, Value).
>
> put(Node, Key, Value) ->
>     gen_server:call({simpledb_svr, Node}, {insert, Key, Value}).

You currently need to provide a spec for both, but for put/2, you
can write " <at> equiv put(node(), Key, Value)" instead of the <at> doc.

   /Richard

<div><div dir="ltr">Thank you. That's good enough.<br><br><div class="gmail_quote">On Mon, Aug 18, 2008 at 1:18 PM, Richard Carlsson <span dir="ltr">&lt;<a href="mailto:richardc <at> it.uu.se">richardc <at> it.uu.se</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">
<div>
<div></div>
<div class="Wj3C7c">Matt Williamson wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; In the docs for gen_server, there for example is call/2,3, two<br>
&gt; signatures for the same base function. How do I use edoc to do something<br>
&gt; similar? Basically I want one argument to be optional without writing a<br>
&gt;  <at> spec for each one. Here's what I have now:<br>
&gt;<br>
&gt; %%===================================================================<br>
&gt; %% API<br>
&gt; %%===================================================================<br>
&gt; %%-------------------------------------------------------------------<br>
&gt; %%  <at> spec put(Node, Key, Value) -&gt; Result<br>
&gt; %% &nbsp; &nbsp; Result = {ok, inserted, Key} | {error, notinserted}<br>
&gt; %% &nbsp; &nbsp; Key = term()<br>
&gt; %% &nbsp; &nbsp; Value = term()<br>
&gt; %% &nbsp; &nbsp; Node = node()<br>
&gt; %%  <at> doc Inserts a Key, Value pair into the server.<br>
&gt; %%-------------------------------------------------------------------<br>
&gt; put(Key, Value) -&gt;<br>
&gt; &nbsp; &nbsp; put(node(), Key, Value).<br>
&gt;<br>
&gt; put(Node, Key, Value) -&gt;<br>
&gt; &nbsp; &nbsp; gen_server:call({simpledb_svr, Node}, {insert, Key, Value}).<br><br>
</div>
</div>You currently need to provide a spec for both, but for put/2, you<br>
can write " <at> equiv put(node(), Key, Value)" instead of the  <at> doc.<br><br>
 &nbsp; &nbsp;/Richard<br>
</blockquote>
</div>
<br>
</div></div>

Gmane