[erlang-questions] Edoc optional function parameters

Richard Carlsson <>
Mon Aug 18 19:18:19 CEST 2008


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



More information about the erlang-questions mailing list