-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecated syntax using the value of .= in the REPL. #26516
Comments
Hm, it's not the assignment to julia> a = zeros(4);
julia> "foo"
"foo"
julia> a .= ones(4); ans
┌ Warning: Deprecated syntax `using the value of `.=``.
└ @ nothing none:0
"foo"
julia> ans
"foo" Also, the work-around is rather ugly: Does the REPL split the input at the julia> Meta.lower(Main, :(a .= ones(4)))
┌ Warning: Deprecated syntax `using the value of `.=``.
└ @ nothing none:0
:($(Expr(:thunk, CodeInfo(:(begin
Core.SSAValue(0) = ones(4)
Core.SSAValue(1) = (Base.broadcast!)(Base.identity, a, Core.SSAValue(0))
return Core.SSAValue(1)
end)))))
julia> Meta.lower(Main, :(a .= ones(4); nothing))
:($(Expr(:thunk, CodeInfo(:(begin
Core.SSAValue(0) = ones(4)
(Base.broadcast!)(Base.identity, a, Core.SSAValue(0))
#= REPL[24]:1 =#
return nothing
end))))) Anyway, what would we want to show and assign to |
I would also much rather just make a final decision here. This deprecation is a hassle and I'd rather not sink more time into it. |
Frankly, I always find the RHS returning behavior at the REPL confusing in any case where the RHS and LHS are not ==, e.g.:
|
...so we should change the result value of |
I don't know, but I wanted to mention it, since it seems related. For completeness of examples and to play devil's advocate, do we have a good example (ignoring the mutating assignment variants for now) where returning the LHS would look super strange? |
Are you suggesting |
One option would be to define |
No, I'm not suggesting anything. I think my main point is that assignment sometimes does non-trivial transformations (e.g. perform the iteration protocol), esp in the broadcasting cast, and esp in the REPL, you're often more interested in what the result of those transformation is than the value that it was transformed from. |
@KristofferC has pointed out that mutating operations generally return the thing that's mutating and |
(after discussion with @fredrikekre earlier today) |
I'm frankly fine with either choice. However, @mbauman pointed out that the left side is more likely to be a "weird" value, like a view, or a special kind of view we introduce for performance (in the near future, for This is a special case of a general property of assignment: in |
General consensus from triage after an extended discussion:
|
As I was writing up the summary from triage, I realized it'd be nice if that |
|
So you are suggesting that, unless you do Why not just define it to return whatever |
What is the mutated object, though? In In Doing it this way allows us to lower
In this case, going through a |
It's whatever gets passed to
Not on the left-hand-side of an assignment.
That is what |
I guess you're worried about In that case, fine, make both Returning |
Yes, that's part of it. What about Do you really use the return value of I'm still not terribly thrilled with how the semantics of |
It makes me uneasy to think that whether a statement With your suggestion, |
That's fair. Even worse: an attempted |
I've seen a suggestion to return |
Returning |
I don't understand what's so bad about just returning the LHS. Sure, it will sometimes be a slightly strange |
This strikes me as violating the principle of least surprise quite badly. An assignment expression that evaluates to something that is neither its left hand side nor its right hand side?! At least returning |
The other argument against the LHS was that Keno's immutable-field-mutation might also lower to something funny, but that doesn't apply to
None of them are all that terrible. I'm convinced that On the other hand, I don't find the golfing |
Data point: Python uses the meaning of tmp = f(); a = tmp; b = tmp; a Of course, in Python the question of what this assignment evaluates to is moot since assignment is a statement, not an expression. I know that @JeffBezanson really dislikes this meaning, but I do think it has the advantage of least surprise for the user – programmers seem to use tmp = f(); b = tmp; a = tmp; tmp There are a couple of things that we've seen that people find surprising about this:
The Python-like interpretation above addresses both of these and doesn't introduce any spooky action at a distance in the presence of typed variables:
I know that @JeffBezanson really hates this interpretation, but I'd like to at least discuss it and understand what the concrete drawbacks are. |
Another possible approach that @Keno suggested on Slack is to make |
This doesn't make sense to me. The Would you also object to having |
Isn't this the same thing: julia> setindex!(a, 3, 2)
3-element Array{Float64,1}:
0.0
3.0
0.0
julia> a[2] = 3
3 |
The difference between |
@mbauman, we document the return value for functions like @KristofferC, my point is that |
The fact that we achieve the mutation through a I think this may be a difference in perspective. When I look at |
Isn't learning that it is actually "just" a I just don't see how returning something that is always useless ( |
@StefanKarpinski If But in julia assignment is a right-associative operator that returns its right argument. So two drawbacks to returning the left side are: (1) We have to evaluate a whole extra expression that we did not have to evaluate before, which could only be less efficient, (2) it could prevent us from having fancy assignment left sides that don't correspond to values in a clear way (for example @Keno 's proposed feature for "mutating immutables"). I also think the alternatives are just more complicated than " |
If we had a Another argument against the LHS is that several of us would like to work on making indexing fuse and participate in broadcasting. We could potentially add a syntax |
Sorry to disturb. I think
|
That's to avoid evaluating the RHS expression multiple times. Since |
Could someone state what the final decision on this ended up to be? What does |
It's back to the previous behavior of just lowering directly to |
Example from the manual
I suspect this warning comes from setting of the
ans
variable in the REPL.The text was updated successfully, but these errors were encountered: