#Beginner Question Slice Defaults
12 messages · Page 1 of 1 (latest)
the default for low in the 2nd one should be 0? so it is the same as s = s[0:2] which should print 2, 3?
the 3rd one uses the default for high which is the length of the array? making it the same as s = s[1:6] which should print 3, 5, 7, 11, 13?
no because at that point s is not the s of line 6
ah so every time there's a change I have to use the latest "iterration" of s
and then go from there
what you have to do depends on what you want to happen
slices are values, s[1:4] creates a new slice, assigning it to s means s has a different value now
more specifically, a slice is modeled as go type slice struct { ptr *T len, cap int }
where ptr points to the first entry (that this slice can see) of the underlying array
s[1:4] creates a new slice that "points to 3"