Slices in D vs Go

Daniel Davidson nospam at spam.com
Sat Oct 19 05:08:48 PDT 2013


On Saturday, 19 October 2013 at 04:52:31 UTC, Jesse Phillips 
wrote:
> Do to the recent slices discussion I did some investigation on 
> what is different in Go. Thus, created this
>
> http://he-the-great.livejournal.com/48672.html

It starts with:
     int[] original;
     original.reserve(5);
     writeln("orig cap: ", original.capacity); // 7
     writeln("orig len: ", original.length); // 0

Further down says: "But to discuss behavior we'll need some 
elements."

and immediately proceeds with code accessing original where no 
data has been added:

     auto slice = original[1..$];
     writeln("slice cap: ", slice.capacity); // 6
     writeln("slice len: ", slice.length); // 2
     original[0]++;
     slice[0]++;
     slice[1]++;
     writeln("orig: ", original); // [1, 2, 3]

I don't know where the [1,2,3] comes from.  The first 
original[1..$] will crash. Maybe you are forgetting the actual 
initialization of original with data?


More information about the Digitalmars-d mailing list