Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
Array.Fill(x, v);
x = v
This is an array assignment with a scalar value.
func fill[T any](x []T, v T) {
for i := range x {
x[i] = v
}
}
fill is generic, it works for any type parameter T
for i := range x {
x[i] = v
}
for i := Low(x) to High(x) do x[i] := v;
my @x = (undef) x $n;
foreach (@x) { $_ = $v }
Create a list with $n elements, each initialized to undef. Then assign $v to each element.
my @x = ($v) x $n;
This defines a new list (@x) and sets $n elements of it to $v. The list grows to length $n. The x operator in this context repeats the left operand $n times.
set_all_elements_to_same_value(X, V) :-
length(X, Length),
length(FilledList, Length),
maplist(=(V), FilledList, X).
x[:] = [v] * len(x)
x.fill(v)