Assignment and mutation are different: http://stackoverflow.com/a/33003055/659248. Note that "pass by reference <https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference>" does not mean what you think it means: pass by reference means passing a value bound to a variable in the calling scope and changing the binding in the calling scope if it's assigned in the called function. What Julia, Python, Ruby, Java and JavaScript all do is called "pass by sharing <https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing>". More info here:
https://www.cs.fsu.edu/~myers/c++/notes/references.html On Wed, Jun 8, 2016 at 1:44 PM, Michele Giugliano <[email protected]> wrote: > Within a function, addressing a generic element of a vector passed to it > results in an external modification of the vector (i.e. argument passed by > reference not value). > > > How do I obtain the same effect when using the vector operator "sum to a > scalar" ? In short, I would like the effect of the two functions f!(z) and > g!(z), defined below, to be the same. > > > function f!(z) > > for i=1:length(z) > > z[i] = 25; > > end > > z = z + 5; > > end > > > function g!(z) > > for i=1:length(z) > > z[i] = 30; > > end > > end > > > Where is my (conceptual) mistake? I would be immensely grateful for your > help and guidance. >
