December 05, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> "Charles Hixson" <charleshixsn@earthlink.net> wrote in message news:3C0C0732.6030108@earthlink.net...
> > Perhaps, as was suggested earlier, there should be an
> > array.maxIndex value? Length is reasonable for the number of
> > elements, but doesn't really match the maximum index. And a
> > fully closed interval is easier to grasp. So one would write:
> > a [0 .. a.maxIndex]
> > (which would be equal to a.length - 1, as long as we agree to
> > use zero based indexing [and if someday it is generalized to
> > n-based indexing, only a minIndex value would need to be added]).
>
> What would maxIndex be for a 0 length array?
NAN, of course!
-BobC
|
December 05, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert W. Cunningham | "Robert W. Cunningham" <rwc_2001@yahoo.com> wrote in message news:3C0D86B9.28E3F0C2@yahoo.com... > > What would maxIndex be for a 0 length array? > > NAN, of course! Actually, index is an integer... |
December 05, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert W. Cunningham | I wish there was a NAN for integer types. -Walter "Robert W. Cunningham" <rwc_2001@yahoo.com> wrote in message news:3C0D86B9.28E3F0C2@yahoo.com... > Walter wrote: > > > "Charles Hixson" <charleshixsn@earthlink.net> wrote in message news:3C0C0732.6030108@earthlink.net... > > > Perhaps, as was suggested earlier, there should be an > > > array.maxIndex value? Length is reasonable for the number of > > > elements, but doesn't really match the maximum index. And a > > > fully closed interval is easier to grasp. So one would write: > > > a [0 .. a.maxIndex] > > > (which would be equal to a.length - 1, as long as we agree to > > > use zero based indexing [and if someday it is generalized to > > > n-based indexing, only a minIndex value would need to be added]). > > > > What would maxIndex be for a 0 length array? > > NAN, of course! > > -BobC > > |
December 05, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
> I wish there was a NAN for integer types. -Walter
Replace the minimum signed integer with NAN. Minimum signed integer
is just a pain in the ass anyway. Don't know what to do about
unsigned integers, mind -- co-opting 0x80000000u would probably
cause some problems.
Joke! Joke!
-R
|
December 05, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Pavel Minayev a écrit :
> "Walter" <walter@digitalmars.com> wrote in message news:9uhjh8$1fhs$2@digitaldaemon.com...
> >
> > <la7y6nvo@shamko.com> wrote in message news:s7citbotd5u.fsf@michael.shamko.com...
> > > INTEGER [ 1 .. 10 ]
> > > INTEGER [ 1 .. 11 )
> > > INTEGER ( 0 .. 10 ]
> > > INTEGER ( 0 .. 11 )
> > >
> > > I'm sure you can see what's going on - the ()'s are used for "open" endpoints, the []'s are used for "closed" endpoints. The resulting syntax was, I thought, pretty intuitive (perhaps because of background in mathematics).
> > >
> > > Maybe a syntax something along these lines could be adopted in D.
> >
> > While that can be done, I'm a little uncomfortable with:
> > 1. the non-matching ( and ] <g>.
> > 2. ] and ) look pretty similar on the screen.
>
> Still... I really like the idea. The syntax is quite intuitive to everybody who knows math a little bit. And you can choose what you want to include and what you don't. IMHO the best syntax proposal on the topic so far. I vote for!
why not just
int a[0..a.lenght[; //note there is two '['
i already proposed something similar that does not thow entousiasm, but it
would be just fine
for me.
Roland
|
December 05, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Roland | "Roland" <rv@ronetech.com> wrote in message news:3C0E6BF2.AD8B160D@ronetech.com... > int a[0..a.lenght[; //note there is two '[' A problem here - this won't be parsed correctly this way: a[0..b[1]]; Since we have [..[ defining a range, it'll interpret it as a[0..b[ |
December 06, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Pavel Minayev | Pavel Minayev wrote:
> "Robert W. Cunningham" <rwc_2001@yahoo.com> wrote in message news:3C0D86B9.28E3F0C2@yahoo.com...
>
> > > What would maxIndex be for a 0 length array?
> >
> > NAN, of course!
>
> Actually, index is an integer...
Well, OK: How about -0 instead? ;^)
-BobC
|
December 06, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert W. Cunningham | "Robert W. Cunningham" <rwc_2001@yahoo.com> wrote in message news:3C0ED470.F388531F@yahoo.com... > > Actually, index is an integer... > > Well, OK: How about -0 instead? ;^) Actually, it's an unsigned integer... muhahahaha Now what? =) |
December 06, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Ok, why don't we all give up and work together? Maybe there can just be 3 equivalent array slice syntaxes: start/length: a[3@2] or a[3 at 2] or .... end exclusive: a(2 .. 5) end inclusive: a[2 .. 4] We can all argue over who gets the coveted [x..y] syntax...but can we all agree that all 3 idioms have their place in the language? -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
December 06, 2001 Re: array slicing ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3C0F0B47.88B4A2C2@deming-os.org... > Ok, why don't we all give up and work together? Maybe there can just be 3 equivalent array slice syntaxes: > > start/length: a[3@2] or a[3 at 2] or .... > end exclusive: a(2 .. 5) > end inclusive: a[2 .. 4] > > We can all argue over who gets the coveted [x..y] syntax...but can we all agree > that all 3 idioms have their place in the language? I agree. Hey, don't forget about cases when one end is inclusive and other isn't: a(2..5]; a[2..5); Personally, I believe that this plus the @ syntax covers the widest possible range and is able to satisfy most programmers. It'd be great to see these things in D. |
Copyright © 1999-2021 by the D Language Foundation