Noob - Getting Started Infinte Loop?

Lennart Ohman <>
Thu Aug 31 10:24:32 CEST 2006


Hi,
the _ (only an underscore) is never bound from efficiency
reasons. For instance:

f(foo,bar) -> ...;
f(frotz,X) -> ...;
f(_,X) -> ....

could be used to indicate in the third clause that Erlang
should not spend time on binding the first argument to a
variable since it will not be used. Actually, if you replace
the third head with f(DontCare,X) -> you will get a compiler
warning. The compiler suspects that you misspelled that variable
name, and it should be one you actually use in the body.

Then you have the possibility of placing an _ in front of
a variable name. Like _dontCare. That will actually make the
variable bound and possible to use (however good Erlang practise
says you shouldn't). The underscore removes the compiler
warnings in this case.

Best Regards
Lennart

-------------------------------------------------------------
Lennart Ohman                   office  : +46-8-587 623 27
Sjoland & Thyselius Telecom AB  cellular: +46-70-552 67 35
Sehlstedtsgatan 6               fax     : +46-8-667 82 30
SE-115 28, STOCKHOLM, SWEDEN    email   : 

> -----Original Message-----
> From:  [mailto:owner-erlang-
> ] On Behalf Of fbg111
> Sent: Thursday, August 31, 2006 12:58 AM
> To: 
> Subject: Re: Noob - Getting Started Infinte Loop?
> 
> 
> 
> ke han wrote:
> >
> > 3 - Also, for efficiency sake, you should name the variable "First"
> > as "_First" to indicate you do not want the value bound.
> >
> 
> I was under the impression so far that all variables in Erlang are bound,
> unless 'bound' means something other than you can't change the value of a
> variable after assignment?  Thanks!
> --
> View this message in context: http://www.nabble.com/Noob---Getting-
> Started-Infinte-Loop--tf2189189.html#a6069968
> Sent from the Erlang Questions forum at Nabble.com.





More information about the erlang-questions mailing list