[erlang-questions] Underscore prefixes

Matthew Dempsky matthew@REDACTED
Fri Apr 18 04:38:54 CEST 2008


On Thu, Apr 17, 2008 at 7:13 PM, Vik Olliver <vik@REDACTED> wrote:
> Underscores before a variable indicate it's basically optional, right?

It simply tells the compiler not to issue a warning if the variable is
not otherwise used.

>  So why would someone do:
>
>  _Result = module:function(X),
>  {response, ok}.
>
>  in their code?

Style maybe.  When matching elements of a tuple, I'll often still
write "_Foo" and "_Bar" (but actually meaningful names) even if I
don't need those elements in case I later need to change the code and
it saves me a little bit of time looking up what the other elements
are again.

This particular case though, it's kinda silly.  Obviously the return
value of a function is its result. :-)



More information about the erlang-questions mailing list