Arrays: Difference between revisions

Content added Content deleted
(→‎{{header|Rust}}: Initial version.)
(Added Self version)
Line 3,992: Line 3,992:
array1 := array3 & array6; # Concatenate two arrays and assign the result to array1.
array1 := array3 & array6; # Concatenate two arrays and assign the result to array1.
end func;</lang>
end func;</lang>

=={{header|Self}}==

The vector protorype represents a fixed size array with polymorphic contents. Vector indexing is zero based.
Fixed size means that once created it is expensive (although not strictly impossible) to resize it. If resizable sequenced collections are wanted, the 'sequence' prototype can be used.
Creating simple vectors:
<lang self>vector copySize: 100</lang>
<lang self>vector copySize: 100 FillingWith: anObject</lang>

A polymorphic vector:
<lang self>(1 & 'Hello' & 2.0 & someObject) asVector</lang>

Using a vector:
<lang self>|v|
"creates an vector that holds up to 20 elements"
v: vector copySize: 20.
"access the first element"
v first printLine.
"access the 10th element"
(v at: 9) printLine.
"put 100 as second value"
vat: 1 Put: 100.</lang>

Enumeration:
<lang self>v do: [:each | each printLine].
v copy mapBy: [:each | each squared].
v copy filterBy: [:each | each > 10].</lang>

Using a squence:
<lang self>|s|
"creates a new sequence"
s: sequence copyRemoveAll.
"add an element"
s addLast: 'Hello'.
"access the first element"
s first printLine.
"remove the first element"
s removeFirst.
"Check size"
s size printLine.</lang>


=={{header|Sidef}}==
=={{header|Sidef}}==