Text editing [Was: Re: #line decoder]

Denis Koroskin 2korden at gmail.com
Mon Sep 29 10:31:50 PDT 2008


On Mon, 29 Sep 2008 02:31:59 +0400, Sergey Gromov <snake.scaly at gmail.com>  
wrote:

> Sun, 28 Sep 2008 16:38:33 -0400,
> bearophile wrote:
>> Real copy of the slice:
>> int[] s = a[2 .. 5];
>>
>> Light copy, by reference only, some possible alternative syntax:
>> int[] s = a[2 .. 5].light;
>> int[] s = a[[2 .. 5]];
>> int[] s = a[2 .. 5].undup;
>> int[] s = a[|2 .. 5|];
>> int[] s = a[{2 .. 5}];
>> int[] s = a{2 .. 5};
>> int[] s = a[(2 .. 5)];
>
> Unfortunately this doesn't address the issue I've faced: readLine
> returns a slice of an internal buffer and there's no way to notice that
> except by RTFM or debugging.

I think it is easy. Adopt a guide-line and make it standard (across the  
library or the whole language):

a) if a const slice is returned then it means that you don't own the data  
but someone else does. You can only read from it (const == readonly).
b) if a mutable slice is returned then you are free to modify it, you are  
the sole owner of it.


More information about the Digitalmars-d-announce mailing list