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

Reactivity bug when changing array values #1219

Closed
thompsonmj opened this issue Jun 4, 2021 · 2 comments
Closed

Reactivity bug when changing array values #1219

thompsonmj opened this issue Jun 4, 2021 · 2 comments

Comments

@thompsonmj
Copy link

Pluto is designed to disallow reassigning variables, but changing the values inside an array is legal. This is a little confusing.

E.g.

array = [1,2,3]
# do stuff with array
array[2] = 22
# do stuff with reassigned array

It seems the indexed array assignment takes precedence rather than the order of the cells for reactivity.

When the cell where array is first assigned is rerun, the # do stuff with array values change to reflect the original assignment.

Then, once another cell is run, these cells revert to the indexed reassignment.

@lungben
Copy link
Contributor

lungben commented Jun 6, 2021

Pluto cannot detect if functions are mutating their input arguments (changing an array element is lowered to setindex!), therefore 2nd cell is considered only as reading array, not as writing to it.
This is both a technical (how can you reliably detect which function argument is mutated?) and conceptual problem (cell order in the notebook should not be relevant, when are you referring to the original and the mutated array?).

The solution is to pass explicitly dependency information by assigning the mutated array to a new label:

begin
array[2] = 22
modified_array = array
end

This way it is ensured that each reference to modified_array has modified_array[2] == 22.
However, array[2] is still undefined - it could contain 2 or 22.

@fonsp
Copy link
Owner

fonsp commented Jun 7, 2021

#564

@fonsp fonsp closed this as completed Jun 7, 2021
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

No branches or pull requests

3 participants