for many of the Erlang exercises the parameters they list for the function are uppercase (Erlang requirement) and preceded with an underscore like
score(_X, _Y) -> undefined.
what’s up with the underscore?
for many of the Erlang exercises the parameters they list for the function are uppercase (Erlang requirement) and preceded with an underscore like
score(_X, _Y) -> undefined.
what’s up with the underscore?
It makes compiler warnings about unused variables go away.
If you had score(X, Y) -> undefined
, you would see warning about X
and Y
being unused.
Due to the fact that all the rebar-projects are warnings_as_errors
this would be annoying, so we prefixed all the variables with an underscore to signal, it is fine for them to not be used.
Thank you so much for the quick reply!
One more thing. What do you mean by rebar-projects?
Rebar is a buildtool for Erlang, and all exercises are delivered with a project file that describes the build.
If you do the exercises locally, might notice that you use rebar eunit
or rebar3 eunit
to run the tests.
The website works a bit differently, though as far as I remember, it also uses warnings as errors for consistency.
Also it is a good habit to not have unused variables, and if you have to, make it explicit.
lol I tried to look up Rebar and I got a bunch of building construction pics!