Julia function argument by reference

前端 未结 4 1678
抹茶落季
抹茶落季 2021-02-05 08:22

The docs say

In Julia, all arguments to functions are passed by reference.

so I was quite surprised to see a difference in the behav

4条回答
  •  青春惊慌失措
    2021-02-05 09:09

    r=r+1 is an Assignment statement, this means it reallocates r, so it no longer refers to its pair in the parent scope. but r[i]=r[i]+1 Mutates r value, mutation is differ from assignment (a good description here), and after that r still refers to its pair variable in the parent scope.

提交回复
热议问题