Skip to content
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

Bugfix in With: Return evaluated result #1194

Merged
merged 2 commits into from
Nov 29, 2024
Merged

Bugfix in With: Return evaluated result #1194

merged 2 commits into from
Nov 29, 2024

Conversation

aravindh-krishnamoorthy
Copy link
Collaborator

@aravindh-krishnamoorthy aravindh-krishnamoorthy commented Nov 28, 2024

Problem

Block[{i = 0}, With[{}, Module[{j = i}, Set[i, i+1]; j]]]

returns 1 whereas the correct answer is 0. This is because, With evaluates the Module expression but erroneously returns the unevaluated version, triggering a second evaluation.

Fix

The fix is to return the evaluated version. With the fix, the above code returns 0 as expected.

@rocky
Copy link
Member

rocky commented Nov 28, 2024

Thanks! Would you add a pytest for this, please?

@aravindh-krishnamoorthy
Copy link
Collaborator Author

Thanks! Would you add a pytest for this, please?

Indeed! Soon will add a pytest...

@rocky
Copy link
Member

rocky commented Nov 28, 2024

LGTM

Copy link
Contributor

@mmatera mmatera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmatera mmatera merged commit 807bd57 into master Nov 29, 2024
13 checks passed
@mmatera mmatera deleted the bugfix_with branch November 29, 2024 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants