News/info on Go and Java
Sergey Gromov
snake.scaly at gmail.com
Thu Nov 26 07:41:25 PST 2009
Wed, 25 Nov 2009 12:27:59 +0300, Denis Koroskin wrote:
> On Wed, 25 Nov 2009 03:03:59 +0300, bearophile <bearophileHUGS at lycos.com>
> wrote:
>
>> This looks a lot like D:
>> http://research.swtch.com/2009/11/go-data-structures.html
>
> Looks like go has arrays that support slices. Do they support appending?
> If so, what's their behavior and how do they solve stomping issues?
Arrays are values and cannot be resized after creation.
var array [10]int;
Arrays can be sliced like in D:
var slice []int = array[5:7];
The length of this slice is len(slice) == 7 - 5 == 2. The *capacity*
of this slice is cap(slice) == 10 - 5 == 5.
You can slice a slice beyond its length, up to capacity:
var slice2 []int = slice[4:5];
Effectively slice is a tail of an array, with optional subdivision into
sub-head and sub-tail.
There is no array nor slice concatenation, nor any other way to change
slice length except slicing.
More information about the Digitalmars-d
mailing list