Functions that end with an exclamation point modify their arguments, but
they can return values just like any other function. For example:
julia> x = [1,2]; y = [3, 4]
2-element Array{Int64,1}:
3
4
julia> append!(x,y)
4-element Array{Int64,1}:
1
2
3
4
julia> z = append!(x,y)
6-element Array{Int64,1}:
1
2
3
4
3
4
julia> z
6-element Array{Int64,1}:
1
2
3
4
3
4
julia> x
6-element Array{Int64,1}:
1
2
3
4
3
4
The append! function takes two arrays, appends the second to the first,
then returns the values now contained by the first array. No recursion
craziness required.
On Thursday, December 11, 2014 1:11:50 AM UTC-6, Sean McBane wrote:
>
> Ivar is correct; I was running in the Windows command prompt and couldn't
> copy and paste so I copied it by hand and made an error.
>
> Ok, so I understand that append!(X,Y) is modifying X in place. But I still
> do not get where the output for the second case, where the result of
> append!(X,Y) is assigned back into X is what it is. It would make sense to
> me if this resulted in a recursion with Y forever getting appended to X,
> but as it is I don't understand.
>
> Thanks.
>
> -- Sean
>
> On Thursday, December 11, 2014 12:42:45 AM UTC-6, Ivar Nesje wrote:
>>
>> I assume the first line should be
>>
>> > X = [1,2]; Y = [3,4];
>>
>> Then the results you get makes sense. The thing is that julia has mutable
>> arrays, and the ! at the end of append! indicates that it is a function
>> that mutates it's argument.
>
>