On Thursday, 30 May 2013 at 18:46:17 UTC, deadalnix wrote:
On Thursday, 30 May 2013 at 18:25:08 UTC, Maxim Fomin wrote:
In neighbor thread (especially from 5 page http://forum.dlang.org/thread/mailman.175.1369540733.13711.digitalmar...@puremagic.com?page=5) there is discussion about current state of definitions in D related to slices, slice expressions and arrays. There is significant contradiction between documentation in different parts of the D site and people who interpret it.

Problem boils down to following:

- in array and type official spec page, dynamic array is defined as T[] type as "Dynamic arrays consist of a length and a pointer to the array data.". The page also describes what slicing is. Also expression page defines what SliceExpression is. Internally dmd follows these conventions.

- in articles part of the site there is article "D Slices" written by Steven Schveighoffer, which abolishes current relevant parts of current spec. According to the article, dynamic array is runtime managed memory which in implementation specific manner provides some set of operation related to arrays. According to the article T[] is by no means a dynamic array, but a slice. The article explicitly claims that spec is wrong.

So, there is contradiction between what T[] is. Either it is a slice (and what is more important, not a dynamic array type) which point by druntime managed dynamic array, or is object of type dynamic array, which may point to heap or stack memory.

Discussion shows that there is no clear consensus on this, so there is need for Walter and Andrei to comment on this.

An array IS a slice. A slice IS an array. Nothing contradict anything.

There is some...peculiar stuff about slices though. If you slice a static array or a pointer and append to it the slice then points to a new distinct GC allocated array. It's not all that different from appending to a slice backed by a dynamic array an exhausted capacity but it can be surprising to people who don't know about this.

Perhaps appending to a slice of non-gc allocated memory should be an error (you can't append to a static array, for instance).

Reply via email to