Documentation for method ASSIGN-POS
assembled from the following pages:
Language documentation: Subscripts §
From Subscripts
(Subscripts) method ASSIGN-POS §
multi method ASSIGN-POS (::?CLASS: , )
Expected to set the element at position $index
to the value $new
. Implementing this is entirely optional; if you don't, self.AT-POS($index) = $new
is used instead, and if you do, you should make sure it has the same effect.
This is meant as an opt-in performance optimization, so that simple assignments like @numbers[5] = "five"
can operate without having to call AT-POS
(which would have to create and return a potentially expensive container object).
Note that implementing ASSIGN-POS
does not relieve you from making AT-POS
an rw
method though, because less trivial assignments/modifications such as @numbers[5]++
will still use AT-POS
.