Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 18, 2003 Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
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 |
December 18, 2003 Re: Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | 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 > > |
December 19, 2003 Re: Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | 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.. |
December 19, 2003 Re: Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | "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 :-( |
December 19, 2003 Re: Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | 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
|
December 19, 2003 Re: Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | 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 |
December 19, 2003 Re: Implicit slice bounding | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | 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
|
Copyright © 1999-2021 by the D Language Foundation