On Thu, May 30, 2013 at 08:46:16PM +0200, 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/[email protected]?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.
I think the confusion comes from the inconsistent terminology used. There is a difference between "array" or "slice", in the sense of a pointer+length pair, and the contents of the array, in the sense of the memory block to contains the array elements. The pointer+length pair is what is visible to the programmer: when you declare T[] or take slices, you're just manipulating these pointer+length pairs. The underlying memory being pointed to, however, is something managed by the D runtime, and isn't directly manipulatable by the programmer. This is what Steven refers to as "dynamic arrays"; he uses the term "slice" for the pointer+length pairs seen by the programmer, whereas I think the spec uses both "array" and "slice" for the pointer+length pair, but leaves the runtime-managed memory blocks unspecified (it doesn't have to be specified, since these memory blocks are supposed to be implementation dependent). As long as you understand the difference between the pointer+length pair and the actual memory containing the array elements, there is no confusion and no contradiction. :) T -- Those who've learned LaTeX swear by it. Those who are learning LaTeX swear at it. -- Pete Bleackley
