-
Notifications
You must be signed in to change notification settings - Fork 231
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
Add augmented assignment operators to Macaulay2 language #3079
Merged
DanGrayson
merged 22 commits into
Macaulay2:development
from
d-torrance:augmented-assignment
Jan 24, 2024
Merged
Add augmented assignment operators to Macaulay2 language #3079
DanGrayson
merged 22 commits into
Macaulay2:development
from
d-torrance:augmented-assignment
Jan 24, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d-torrance
force-pushed
the
augmented-assignment
branch
from
January 21, 2024 13:55
d55cc5e
to
e2075d1
Compare
One for most flexible binary operators (omitting ones that would introduce ambiguity or give syntax errors) with the same precedence as = (to match C).
This way it won't complain when we try to install a function with two arguments.
They're binary and they're flexible, but they're a little different than the members of flexibleBinaryOperators. In particular, we don't want to run installAssignmentMethod on them, which is why we keep them separate from flexibleBinaryOperators.
If the method returns the "Default" symbol, then fall back to the usual behavior. This is useful for example for the Python package, where we'd like += to call the __iadd__ method, but only if it exists.
This will be used by augmented assignment. The problem was that we first want to check if a user-defined method for augmented assignment is installed, which requires evaluating the code on the left-hand side of the operator. But if we *don't* use a user-defined method (which will be the case most of the time), then we want the original code, since that's what the binary operators expect. The solution is to create a member of the Code union that saves the evaluated code. Then we can evaluate early on but still call the binary operators later if need.
Evaluate everything immediately but store it as evaluatedCode for later.
d-torrance
force-pushed
the
augmented-assignment
branch
from
January 24, 2024 05:07
e2075d1
to
7d8107a
Compare
By the way, have you seen #1596? |
Not until you pointed it out, but I like the idea a lot! The implementation would be pretty similar to this PR, I think. |
Yeah, I figured it might be easy to do if you're already familiar with that part of the code. |
This was referenced Jan 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For most flexible binary operators in Macaulay2, we add a corresponding augmented assignment operator. (This is something that would be very useful if/when we add atomic integers at top-level -- see #3044.)
Here's the proposed documentation for more information:
Note that not every flexible binary operator is supported, e.g., it wouldn't make sense to have an augmented assignment operator for
==
since===
is already in use.As proof of concept, we update a few places in Core with
i = i + 1
to usei += 1
and also add augmented operator support to thePython
package.