don't even pass it to a function, just do
b = b .+ 5
wherever you need to.
On Thursday, May 1, 2014 8:23:51 PM UTC+8, Kaj Wiik wrote:
>
> OK, thanks, makes sense. But how to change the original instance, is
> looping the only way?
>
> On Thursday, May 1, 2014 3:12:51 PM UTC+3, Freddy Chua wrote:
>>
>> 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
>>>
>>