!- it’s just an agreement; this is not a requirement for mutating functions.
Any function can mutate its inputs. But so that it is clear that he is doing this, we suffix him with !.
, , .
String s, Tuples, Int64 s, Float32 ..
, immutable.
, , Vectors.
,
.
, , , 2.
(fill!(v,2) - , , , )
, v :
function right1_fill_with_twos!(v::Vector{Int64})
v[:]=[2 for ii in 1:length(v)]
end
, :
function right2_fill_with_twos!(v::Vector{Int64})
for ii in 1:length(v)
v[ii]=2
end
v
end
, :
, v
function wrong1_fill_with_twos!(v::Vector{Int64})
v=[2 for ii in 1:length(v)]
end
, :
function wrong2_fill_with_twos!(v::Vector{Int64})
u = Vector{Int64}(length(v))
for ii in 1:length(v)
u[ii]=2
end
v = u
end
, (, Int64 s),
- .
, , , , ( ), . pass , .
, () Java