Inability to dup/~ for const arrays of class objects
Diggory
diggsey at googlemail.com
Thu May 30 01:11:07 PDT 2013
On Thursday, 30 May 2013 at 07:15:39 UTC, Jonathan M Davis wrote:
> On Thursday, May 30, 2013 09:01:06 Maxim Fomin wrote:
>> > The article about slices on this site -
>> > http://dlang.org/d-array-article.html is perfectly correct.
>>
>> No, the article is incorrect in vocabulary because it
>> contradicts
>> to the spec definitions, and spec incompletence is not a reason
>> to dilute what is already defined. What actually happens is:
>> 1) T[] is defined as dynamic array, PostfixExpression [ ] is
>> defined as SliceExpression.
>> 2) Array article calls dynamic arrays as slices. Since notion
>> of
>> dynamic array is occupied, the article calls GC memory as
>> dynamic
>> array. This is a complete contradiction to spec.
>> 3) Folks start using these misleading definitions.
>>
>> This actually leads to incorrect assumptions, as was pointed
>> out
>> previously that dynamic array points only to runtime memory
>> (which is not always the case).
>
> Much as I love that article, I really don't like the fact that
> it tries to
> claim that dynamic arrays and slices are two different things,
> since they
> aren't. T[] is a dynamic array _and_ a slice, and for the
> article to be
> completely correct in its terminology, it would actually be
> incorrect to refer
> to _anything_ in D as a dynamic array, as it would be something
> completely
> internal to the runtime. T[] would be only a slice, and the
> type system
> wouldn't have dynamic arrays in it anywhere.
>
> The runtime holds the memory that dynamic arrays / slices refer
> to, but I
> really wish that that article had not referred to that
> underlying memory as
> being the dymanic array as opposed to simply a block of memory
> that the
> runtime gave slices to, letting the slices be referred to as
> dynamic arrays
> like they are.
>
> I would argue that all dynamic arrays are array slices and vice
> versa. And
> that's how std.traits.isDynamicArray treats them as well.
>
> - Jonathan M Davis
But it's clearly not the case that all slices are dynamic
arrays... A dynamic array is already a well-established term to
mean an array allocated on the heap. Slices can point to arrays
on the stack.
More information about the Digitalmars-d
mailing list