Variable instances (Re: Trace on Variable assignment)

Richard Carlsson richardc@REDACTED
Fri Nov 10 12:23:33 CET 2000

On Thu, 9 Nov 2000, Vance Shipley wrote:

> }  If this is really something which people would like lint to check and 
> }  warn I would prefer just to use the variable-name-ending-with-index 
> }  convention.  Lint already checks for singeton variables if you ask it, 
> }  just use the option 'warn_unused_vars'.  It is, however, a bit of a 
> }  sledgehammer.  It ignores variables starting with "_", eg. _Temp.
> This pokes at a pet peeve of mine.
> When I reverse engineered the AbsForm I wanted to have the code serve to 
> document it.  I wanted to match on:
> {clause,_Line,[{_Type,_Line,Arg1},{_Type,_Line,Arg2}],_Guard,ClauseList}
> I had thought that by prepending an underscore the variable was anonymous.
> I quickly learned that it is not, only a single underscore is treated as
> anonymous.  I would prefer that any variable with a leading underscore was
> treated as anonymous so that the above would work if Arg2 had a different 
> line number than Arg1 or the types of the arguments were different.

Treating any underscore-prefixed variables as anonymous would break a lot
of existing code. However, a nice compromise could be to let the compiler
warn about unused variables (when the `warn_unused_vars' option is set)
*unless* the variable is underscore-prefixed.

That means that typical errors like:

		S1 = foo(S0),
		S2 = bar(S0),
		S3 = foo(S2),

will be warned about (S1 is not used), but no complaints would be issued
about your example {clause,_Line,[{_Type,...

	/Richard Carlsson

Richard Carlsson (richardc@REDACTED)   (This space intentionally left blank.)
E-mail: Richard.Carlsson@REDACTED	WWW:

More information about the erlang-questions mailing list