[]= multimethod

Methods

[]=(arr:Arr, range:NumRange, replacement:Arr)
Set array elements at specified indexes.

Returns

replacement
[]=(arr:Arr, idx:Int, v:Any)
Set element at the given index or throw IndexNotFound if the index is out of range.

Returns

v
[]=(s:Str, range:NumRange, replacement:Str)
Change substring

Returns

replacement

Example

s="abcd"; s[1..3]="X"; s  # "aXd"
[]=(h:Hash, k:Any, v:Any)
Set hash value.

Parameters

hTarget hash
kKey
vValue

Returns

v

Example

h = {"a": 1}
h["a"] = 2
h["a"]  # 2
[]=(al:ArrLike, idx:Int, x:Any) Source: stdlib.ngs:1506
Get element from the underlying array.
[]=(hl:HashLike, k:Any, v:Any) Source: stdlib.ngs:1634
Set value.

Automatically called by NGS for syntax

your_hashlike[k] = v
[]=(arr:Arr, idx:Int, val:Any) Source: stdlib.ngs:2905
Set array element by index from the end (negative indexes handler). Throws IndexNotFound if abs(idx) > len(arr).

Parameters

idxNegative index

Example

a = [1, 2, 3]; a[-1] = 99  # [1, 2, 99]
[]=(arr:Arr, r:PredRange, replacement:Arr) Source: stdlib.ngs:2984
Replace array elements.

Parameters

arrArray to operate on.
rRange of elements to replace.
replacementNew elements.

Example

a = %[a1 a2 b1 b2]
a[/^a/.../^b/] = [7]  # a == [7, 'b2']
MARKERS = '# generated - start'..'# generated - end'
text[MARKERS] = newly_generated_content_lines
[]=(h:Hash, k:Any, v:Any)
Setting same key twice is a bug. If it happens, augment_types() works on one objects but other objects are used later.