www.digitalmars.com         C & C++   DMDScript  

D - Implicit slice bounding

reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
Any chance we might get the implicit slice bounding?

Currently the following forms are valid:

thing[]         // [0, thing.length)
thing[f .. t]     // [f, t)

I'd like it if we could also do the following:

thing[f .. ]     // [f, thing.length)
thing[ .. t]     // [0, t)

The problematic part is that a simple implementation would be

opSlice(T from);
opSlice(T to);

How would we distinguish between the two? Without having some nasty kludges,
we'd probably be restricted to only one of the two extra slice operations,
and I would suggest the first one would be the one most commonly required.

Of course, if they'd both be commonly required (or at least it's not 1000 to
1), then it's probably best to just leave it as is. Ho hum.

Although, we could have

opSliceF(T from);
opSliceT(T to);

Thoughts?

Matthew
Dec 18 2003
next sibling parent "Mark J. Brudnak" <mjbrudna oakland.edu> writes:
There was a lengthy discussion regarding this a couple of weeks ago:

http://www.digitalmars.com/drn-bin/wwwnews?D/19634


"Matthew" <matthew.hat stlsoft.dot.org> wrote in message
news:brt4c7$1f7h$1 digitaldaemon.com...
 Any chance we might get the implicit slice bounding?

 Currently the following forms are valid:

 thing[]         // [0, thing.length)
 thing[f .. t]     // [f, t)

 I'd like it if we could also do the following:

 thing[f .. ]     // [f, thing.length)
 thing[ .. t]     // [0, t)

 The problematic part is that a simple implementation would be

 opSlice(T from);
 opSlice(T to);

 How would we distinguish between the two? Without having some nasty
kludges,
 we'd probably be restricted to only one of the two extra slice operations,
 and I would suggest the first one would be the one most commonly required.

 Of course, if they'd both be commonly required (or at least it's not 1000
to
 1), then it's probably best to just leave it as is. Ho hum.

 Although, we could have

 opSliceF(T from);
 opSliceT(T to);

 Thoughts?

 Matthew
Dec 18 2003
prev sibling next sibling parent reply davepermen <davepermen_member pathlink.com> writes:
In article <brt4c7$1f7h$1 digitaldaemon.com>, Matthew says...
Any chance we might get the implicit slice bounding?

Currently the following forms are valid:

thing[]         // [0, thing.length)
thing[f .. t]     // [f, t)

I'd like it if we could also do the following:

thing[f .. ]     // [f, thing.length)
thing[ .. t]     // [0, t)

The problematic part is that a simple implementation would be

opSlice(T from);
opSlice(T to);

How would we distinguish between the two? Without having some nasty kludges,
we'd probably be restricted to only one of the two extra slice operations,
and I would suggest the first one would be the one most commonly required.

Of course, if they'd both be commonly required (or at least it's not 1000 to
1), then it's probably best to just leave it as is. Ho hum.

Although, we could have

opSliceF(T from);
opSliceT(T to);

Thoughts?

Matthew
what if opSlice just gets 0, or length, as first, or last, parameter? that way opSlice would handle all situations..
Dec 19 2003
parent reply Andy Friesen <andy ikagames.com> writes:
davepermen wrote:

 what if opSlice just gets 0, or length, as first, or last, parameter? that way
 opSlice would handle all situations..
That only works for sequences. What if opSlice accepted a char[]? The only solution I see is adding opSliceFrom() and opSliceTo(). -- andy
Dec 19 2003
next sibling parent davepermen <davepermen_member pathlink.com> writes:
why?

[ .. x] shall be equal to [0 .. x], and [x .. ] shall be equal to [x ..
a.length], not?

if it shall be equal, then make it equal => just send 0 or a.length as first or
second parameter to the ordinary slice function. whats the problem?

In article <brvcui$1rr5$1 digitaldaemon.com>, Andy Friesen says...
davepermen wrote:

 what if opSlice just gets 0, or length, as first, or last, parameter? that way
 opSlice would handle all situations..
That only works for sequences. What if opSlice accepted a char[]? The only solution I see is adding opSliceFrom() and opSliceTo(). -- andy
Dec 19 2003
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
Andy Friesen wrote:
 That only works for sequences.  What if opSlice accepted a char[]?
 
 The only solution I see is adding opSliceFrom() and opSliceTo().
STL-like solution: properties for start and end of the array, which may return an iterator and not an index? The [] operator may also return an iterator? -eye
Dec 19 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Matthew" <matthew.hat stlsoft.dot.org> wrote in message
news:brt4c7$1f7h$1 digitaldaemon.com...
 The problematic part is that a simple implementation would be

 opSlice(T from);
 opSlice(T to);

 How would we distinguish between the two?
Yup. That's why it's not in the language :-(
Dec 19 2003