[Gambas-user] Would an ArrayList datatype be helpful for gambas users?

T Lee Davidson t.lee.davidson at gmail.com
Mon Sep 11 17:37:04 CEST 2023


On 9/11/23 04:18, Gianluigi wrote:
> You made me want to check out Bjarne Stroustrup's book.
> 
> Slice is well explained, unfortunately it is 'way' beyond my mental capabilities.
> 

I have to doubt, Gianluigi, that slices are beyond your comprehension. They are actually not complex. Perhaps that book's 
explanation was rather convoluted.

A slice is, simply stated, a limited view of an array.

Suppose we could do this:

Dim aStrings As String[] = ["one", "two", "three", "four", "five", "six", "seven"]
Dim aSlice As Slice = aStrings.Slice(2, 3) ' Syntax equals Slice(startIndex, Length) [ Except in Python :-\ ]

The slice's view of the underlying array would consist of only the values ["three", "four", "five"] and would be indexed 
starting at zero.

Print aSlice[1] ' Would print "four"

Since a slice is not a copy of a subset of an array (but holds a reference to the underlying array), changing a value in the 
slice also changes the referenced value in the array:

aSlice[1] = "nine"
' aStrings now equals ["one", "two", "three", "nine", "five", "six", "seven"]

See? Simple. (But, I may not have explained it very well either.)


-- 
Lee



More information about the User mailing list