Thread overview
Better slicing
Mar 08, 2006
NN
Mar 08, 2006
Hasan Aljudy
Mar 08, 2006
Tom
Mar 09, 2006
Lionello Lunesu
Mar 09, 2006
Oskar Linde
Mar 10, 2006
Lionello Lunesu
Mar 09, 2006
Bruno Medeiros
Mar 09, 2006
Sean Kelly
March 08, 2006
What about more powerful slicing, like e.g. in Python ?

char[] x;

char[] y = x[0 : x.size : 1];
char[] y = x[x.size : 1]; // Same

char[] z = x[x.size : 0 : -1]; // Reverse
char[] z = x[x.size :: -1]; // Same

// Maybe with D syntax
char[] x;

char[] y = x[0 .. x.size .. 1];
char[] y = x[x.size .. 1]; // Same

char[] z = x[x.size .. 0 .. -1]; // Reverse
char[] z = x[x.size .. .. -1]; // Same


March 08, 2006
NN wrote:
> What about more powerful slicing, like e.g. in Python ?
> <snip>
> char[] y = x[0 .. x.size .. 1];

What's that supposed to mean?
March 08, 2006
In article <dun61g$30be$1@digitaldaemon.com>, NN says...
>
>What about more powerful slicing, like e.g. in Python ?
>
>char[] x;
>
>char[] y = x[0 : x.size : 1];
>char[] y = x[x.size : 1]; // Same
>
>char[] z = x[x.size : 0 : -1]; // Reverse
>char[] z = x[x.size :: -1]; // Same
>
>// Maybe with D syntax
>char[] x;
>
>char[] y = x[0 .. x.size .. 1];
>char[] y = x[x.size .. 1]; // Same
>
>char[] z = x[x.size .. 0 .. -1]; // Reverse
>char[] z = x[x.size .. .. -1]; // Same

I think it's enough how it is now. We'll never reach 1.0 if we keep adding "luxuries" to the language, of course it's my humble oppinion. Instead I would suggest to complete unfinished features, fix bugs and, if it is possible, to make the almighty constness implementation in some way ;-).

Tom;
March 08, 2006
Tom wrote:
> In article <dun61g$30be$1@digitaldaemon.com>, NN says...
>> What about more powerful slicing, like e.g. in Python ?
>>
>> char[] x;
>>
>> char[] y = x[0 : x.size : 1];
>> char[] y = x[x.size : 1]; // Same
>>
>> char[] z = x[x.size : 0 : -1]; // Reverse
>> char[] z = x[x.size :: -1]; // Same
>>
>> // Maybe with D syntax
>> char[] x;
>>
>> char[] y = x[0 .. x.size .. 1];
>> char[] y = x[x.size .. 1]; // Same
>>
>> char[] z = x[x.size .. 0 .. -1]; // Reverse
>> char[] z = x[x.size .. .. -1]; // Same
> 
> I think it's enough how it is now. We'll never reach 1.0 if we keep adding "luxuries" to the language, of course it's my humble oppinion. Instead I would suggest to complete unfinished features, fix bugs and, if it is possible, to make the almighty constness implementation in some way ;-).

I agree. I think we can already do all these with the currently implemented slicing and .reverse-operations. The syntax with negative indices IMHO doesn't fit in D.

-- 
Jari-Matti
March 09, 2006
To reverse an array is a costly operation, and it would not be a good idea to hide it behind a fancy operator, it will hide the penalty.

L.

"NN" <NN_member@pathlink.com> wrote in message news:dun61g$30be$1@digitaldaemon.com...
> What about more powerful slicing, like e.g. in Python ?
>
> char[] x;
>
> char[] y = x[0 : x.size : 1];
> char[] y = x[x.size : 1]; // Same
>
> char[] z = x[x.size : 0 : -1]; // Reverse
> char[] z = x[x.size :: -1]; // Same
>
> // Maybe with D syntax
> char[] x;
>
> char[] y = x[0 .. x.size .. 1];
> char[] y = x[x.size .. 1]; // Same
>
> char[] z = x[x.size .. 0 .. -1]; // Reverse
> char[] z = x[x.size .. .. -1]; // Same
>
> 


March 09, 2006
Lionello Lunesu wrote:
> "NN" <NN_member@pathlink.com> wrote in message
> news:dun61g$30be$1@digitaldaemon.com...
>> What about more powerful slicing, like e.g. in Python ?
>>
>> char[] x;
>>
>> char[] y = x[0 : x.size : 1];
>> char[] y = x[x.size : 1]; // Same
>>
>> char[] z = x[x.size : 0 : -1]; // Reverse
>> char[] z = x[x.size :: -1]; // Same
>>
>> // Maybe with D syntax
>> char[] x;
>>
>> char[] y = x[0 .. x.size .. 1];
>> char[] y = x[x.size .. 1]; // Same
>>
>> char[] z = x[x.size .. 0 .. -1]; // Reverse
>> char[] z = x[x.size .. .. -1]; // Same

This has similarities to Norbert Nemec's suggestion from 2 years ago:

http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html

> To reverse an array is a costly operation, and it would not be a good idea to hide it behind a fancy operator, it will hide the penalty.

Reversing arrays doesn't have to be expensive if you have strided array references. (By this, I'm not suggesting that D should make simple 1-D dynamic arrays strided.)

(Sorry for reversing the top-posting.)

/Oskar



March 09, 2006
NN wrote:
> What about more powerful slicing, like e.g. in Python ?
> 
No.

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
March 09, 2006
NN wrote:
> What about more powerful slicing, like e.g. in Python ?

I thought about this while reading up on Ruby recently, but I like that the current syntax doesn't have any 'hidden' costs associated with it--no memory is allocated, functions run to manipulate data, etc.  So I would not like to see slicing expanded, even if it would be convenient in some cases.


Sean
March 10, 2006
>> To reverse an array is a costly operation, and it would not be a good idea to hide it behind a fancy operator, it will hide the penalty.
>
> Reversing arrays doesn't have to be expensive if you have strided array references. (By this, I'm not suggesting that D should make simple 1-D dynamic arrays strided.)

How does striding improve a reverse on a 1-D array?

>
> (Sorry for reversing the top-posting.)

No problem, it makes more sense  :)

L.