What are the exact differences between underscore variables and a named variable that starts with underscore from the Erlang compiler point of view (apart from adding readability to the code)?
For example are _ and _Var different?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The don’t care variable
_is a VERY SPECIAL variable which matches anything and is NEVER bound to a value. It is used when I know there is something there but I don’t care what the value is and I will never use. Seeing_is never bound it can not be used in an expression and the compiler flags it as an error.Variables like
_Varare perfectly normal variables which you can match against and will be bound to values which means they can be used in expressions. Prefixing a variable with_is about intent. The compiler normally warns you about a variable which is bound in a pattern but is never used, often a sign of an error. But the compiler does not warn for variables prefixed with_like in_Var. The intent being that I want to give the variable a name, naming things is good, but that I know I will never use it.Remember that
_is really the only special variable and that_Varare normal variables and behave as such if used. If you are feeling perverse then you could prefix all your variables with_and everything will still work.