[erlang-questions] Compiler to warn on used underscore-variables

Tony Arcieri tony@REDACTED
Tue Jan 5 09:34:10 CET 2010


2010/1/5 Zoltan Lajos Kis <kiszl@REDACTED>

> I also understand that many compiler warnings (unused variable, wrong no.
> of args in format call, etc.) are output because there is a clear sign of
> a (semantic) mistake and not because of the source code being invalid.
> So I believe that the current behavior of not warning about a most
> probable mistake with _Var variables is the counter-intuitive one.
>

Along with single assignment there exists a whole class of errors where you
may mistakenly use a previously bound variable in a pattern intending to use
an unbound one.  This has nothing to do with a '_' prefix on them at all,
rather it's simply a class of errors that exist with single assignment and
pattern matching.

There is no general solution to this problem either, any more than there is
a general solution to accidently destructively rebinding a variable then
assuming you were referencing a previous version in languages that support
destructive assignment.

I'm not sure what alternative you're proposing.  Would you prefer all
variables prefixed with an underscore have the same semantics as '_'?

No compiler is going to be able to think for you.

-- 
Tony Arcieri
Medioh! A Kudelski Brand


More information about the erlang-questions mailing list