b = b .+ 5 

creates a new instance of an array, so the original array pointed to by "b" 
is not changed at all.



On Thursday, May 1, 2014 7:39:14 PM UTC+8, Kaj Wiik wrote:
>
> As a new user I was surprised that even if you change the value of 
> function arguments (inside the function) the changes are not always visible 
> outside but in some cases they are.
>
> Here's an example:
>
> function vappu!(a,b)
>        a[3]=100
>        b = b .+ 5
>        (a,b)
> end
>
> c = [1:5]
> d = [1:5]
>
> vappu!(c,d)
> ([1,2,100,4,5],[6,7,8,9,10])
>
> c
> 5-element Array{Int64,1}:
>    1
>    2
>  100
>    4
>    5
> d
> 5-element Array{Int64,1}:
>  1
>  2
>  3
>  4
>  5
>
>
> Should I loop over arrays explicitly, what is happening in b = b .+ 5 ?
>
> Thanks,
> Kaj
>

Reply via email to