The Julia 1.7.3 documentation says this:
“”"A particular class of variable names is one that contains only underscores. These identifiers can only be
assigned values but cannot be used to assign values to other variables. More technically, they can only be
used as an L-value, but not as an R-value:
julia> x, ___ = size([2 2; 1 1])
julia> y = ___
ERROR: syntax: all-underscore identifier used as rvalue"“”
But then I tried this in my Jupiter notebook and it raised an error:
Julia> x, ___ = size([2 2; 1 1])
all-underscore identifier used as rvalue
 top-level scope
@ ./boot.jl:373 [inlined]
 include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196
Is this situation using the underscore variable, ___, as an r-value?
I think the documentation is imprecise, I am not sure if
___ alone counts as an rvalue, but the documentation could have said just “A particular class of variable names is one that contains only underscores. These identifiers can only be assigned values. More technically, they can only be used as an L-value.”. The behaviour is expected, you should not be able to “recover” the value assigned to an underscore variable.
Oh I thought as much. And as at yesterday I finally did some research on the L-vaue and R-value thing and finally saw that there are actually 3 types in reality computer programming: ‘L-values’, ‘non-L values’, ‘R-values’.
An L-value as we all know it is everything on the left-hand side of an assignment: x = 2 + 3, so x is an L-value
A non-L-value is an expression that is not an l-value: x + 1, this would output as 6 in the REPL, but its just not an l-value.
Then we have the R-value, which is everything on the right hand side of the assignment, x = 1 + 3, so 1 + 3 here is an R-value.
The documentation could have stated that explicitly, that 'all-underscore variables cannot be r-value or non-l-values, but they didn’t. This is just one of the few stress we are going to pass through as being early adopters. A lot of people coming into the language aren’t reading the documentation, so they won’t be seeing all this. But does who are, should be posing an hand of help to the documentation writers.
At this point (after 1.0), I would not consider using Julia early adoption anymore.
Solving such documentation problems is incredibly simple, you just need to click “Edit on Github” in the top-right of the page, SIgn in GitHub (if you are not), and then click in the pencil icon in the file header, make the edit, and “Propose changes”, and “Open a pull request”.
Here, it is done: Change description of underscore-only variables by henriquebecker91 · Pull Request #45964 · JuliaLang/julia · GitHub
Funny enough, I don’t know how to fully use GitHub yet since I’m more focused on learning the language’s numeric types and data structures before reading other people’s code. But thanks for doing that