-
-
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
In-place assignment syntax #4019
Comments
For reference, here are the current bang functions exported in base:
|
How do you handle cases where the assigned variable is present in the other arguments to the function, e.g. |
I could imagine annotating the parameters to functions to indicate which values are outputs, and letting the compiler use that as a hint as to where the LHS variable might go. But it sounds somewhat complicated. |
Jeff and I had discussed allowing something like |
The |
An |
Compile-time sorting of keyword arguments isn't implemented yet but will be.
|
Syntax consideration: I know |
yeah, that's a fair point, @pao. |
I'm wondering if the interpretation of |
(To clarify, reasonable as "elementwise assignment" and used for inplace assignment...) |
If the semantics we pick are element-wise, |
|
dup of #249 |
Reference? I thought this was just the name for assignment in some languages, e.g. Algol and Pascal. In Mathematica it's the difference between immediate and delayed assignment, iirc. |
Go uses := to introduce a new variable where the type is infered from the value that is assigned, so that you don't have to declare the type fo the variable. |
Yes, that usage I was aware of. |
I'm thinking mostly of pascal, but := is commonly used as an updating assignment operator in pseudocode, to distinguish it from mathematical =. |
In #3950, people restarted the debate about an in-place assignment operator. The preferred proposal was a
.=
operator that would make things likeA .= B + C
equivalent to something like+!(A, B, C)
.If one follows a convention in which the mutated arguments for an in-place operation are always the first arguments, then it's trivial to translate between the proposed syntactic sugar
o1, o2, ... .= f(i1, i2, ...)
and the existing solution,f!(o1, o2, ..., i1, i2, ...)
. Following a suggestion from @lindahua, the Distributions package has tried to structure its functions so that in-place and pure functions can be readily translated back-and-forth in this way.Pros:
.=
with=
in most assignment calls..=
if we can't agree on the addition of a new assignment operator.Cons:
+!
,-!
, etc. Many of these exist in NumericExtensions, but committing to this proposal requires making the newly document!
convention into something more meaningful in the language. More problematically, this proposal makes the suffixes of function names into something more than a mere convention. Arguably what we want is something built into the language at a deeper level.A_mul_B
work this way, functions likerand!
do not. Making the language consistent with the proposed argument ordering convention would involve massive code breakage.I think this proposal isn't great, but I wanted to get the debate going again.
The text was updated successfully, but these errors were encountered: