www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Better slicing

reply NN <NN_member pathlink.com> writes:
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
next sibling parent 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
prev sibling next sibling parent reply Tom <Tom_member pathlink.com> writes:
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
parent =?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
prev sibling next sibling parent reply "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
parent reply 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
parent "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
prev sibling next sibling parent 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
prev sibling parent Sean Kelly <sean f4.ca> writes:
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
Mar 09 2006