## digitalmars.D - Better slicing

• NN (12/12) Mar 08 2006 What about more powerful slicing, like e.g. in Python ?
• Hasan Aljudy (2/5) Mar 08 2006 What's that supposed to mean?
• Tom (6/18) Mar 08 2006 I think it's enough how it is now. We'll never reach 1.0 if we keep addi...
• Lionello Lunesu (5/18) Mar 08 2006 To reverse an array is a costly operation, and it would not be a good id...
• Oskar Linde (8/30) Mar 09 2006 This has similarities to Norbert Nemec's suggestion from 2 years ago:
• Bruno Medeiros (5/7) Mar 09 2006 No.
```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
```
Mar 08 2006
Hasan Aljudy <hasan.aljudy gmail.com> writes:
```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?
```
Mar 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;
```
Mar 08 2006
=?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
```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
```
Mar 08 2006
"Lionello Lunesu" <lio remove.lunesu.com> writes:
```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

```
Mar 08 2006
Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
```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
```
Mar 09 2006
"Lionello Lunesu" <lio remove.lunesu.com> writes:
``` 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.
```
Mar 10 2006
Bruno Medeiros <daiphoenixNO SPAMlycos.com> writes:
```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
```
Mar 09 2006
Sean Kelly <sean f4.ca> writes:
```NN wrote:
What about more powerful slicing, like e.g. in Python ?