Jump to page: 1 27  
Page
Thread overview
array slicing ranges
Nov 19, 2001
Sean L. Palmer
Nov 19, 2001
Pavel Minayev
Nov 20, 2001
Walter
Nov 20, 2001
Russell Borogove
Nov 20, 2001
Walter
Nov 19, 2001
Walter
Nov 19, 2001
Russ Lewis
Nov 20, 2001
Walter
Nov 20, 2001
Pavel Minayev
Nov 20, 2001
Walter
Nov 20, 2001
Sean L. Palmer
Nov 20, 2001
Walter
Nov 20, 2001
Russ Lewis
Nov 20, 2001
Pavel Minayev
Nov 20, 2001
Pavel Minayev
Dec 02, 2001
nancyetroland
Dec 02, 2001
nancyetroland
Dec 02, 2001
Walter
Dec 02, 2001
Pavel Minayev
Dec 02, 2001
Walter
Dec 02, 2001
Sean L. Palmer
Dec 03, 2001
a
Dec 03, 2001
la7y6nvo
Dec 04, 2001
Walter
Dec 04, 2001
Pavel Minayev
Dec 05, 2001
Roland
Dec 05, 2001
Pavel Minayev
Dec 06, 2001
la7y6nvo
Dec 06, 2001
Russell Borogove
Dec 07, 2001
Pavel Minayev
Dec 07, 2001
Walter
Dec 07, 2001
Pavel Minayev
Re: array slicing ranges and string char positions
Sep 08, 2002
Mark Evans
Sep 12, 2002
Walter
Sep 14, 2002
Mark Evans
Dec 07, 2001
Walter
Dec 07, 2001
Pavel Minayev
Jan 17, 2002
OddesE
Dec 03, 2001
Charles Hixson
Dec 04, 2001
Walter
Dec 04, 2001
Pavel Minayev
Dec 05, 2001
Pavel Minayev
Dec 06, 2001
Pavel Minayev
Dec 05, 2001
Walter
Dec 05, 2001
Russell Borogove
Nov 20, 2001
Walter
Nov 21, 2001
Russell Borogove
Nov 21, 2001
Walter
Nov 21, 2001
Russ Lewis
Nov 22, 2001
Walter
Nov 22, 2001
Russ Lewis
Nov 22, 2001
Walter
Nov 22, 2001
Pavel Minayev
Nov 22, 2001
Rajiv Bhagwat
Nov 22, 2001
Pavel Minayev
Nov 22, 2001
Russ Lewis
Nov 22, 2001
Walter
Apr 18, 2004
Scott Egan
Dec 06, 2001
Russ Lewis
Dec 06, 2001
Pavel Minayev
Dec 06, 2001
Russ Lewis
Dec 06, 2001
Roland
Dec 06, 2001
Roland
Dec 06, 2001
Roland
November 19, 2001
From The D Programming Language, arrays section:  Is this last bit about  b = a[0 .. a.length]  true, or should it actually be  b = a[0 .. a.length-1] ?   In other words, are ranges inclusive, or not?

Sean


Slicing
Slicing an array means to specify a subarray of it. For example:
	int a[10];	declare array of 10 ints
	int b[];

	b = a[1..3];	a[1..3] is a 3 element array consisting of
			a[1], a[2], and a[3]

The [] is shorthand for a slice of the entire array. For example, the
assignments to b:
	int a[10];
	int b[]

	b = a;
	b = a[];
	b = a[0 .. a.length];

are all semantically equivalent.




November 19, 2001
"Sean L. Palmer" <spalmer@iname.com> wrote in message news:9tai22$1fok$1@digitaldaemon.com...
> From The D Programming Language, arrays section:  Is this last bit about
b
> = a[0 .. a.length]  true, or should it actually be  b = a[0 .. a.length-1] ?   In other words, are ranges inclusive, or not?

    "s[0..4] = ...  // error, only 3 elements in s"

So ranges are inclusive, and you get an exception if
you write s[0..s.length].



November 19, 2001
"Sean L. Palmer" <spalmer@iname.com> wrote in message news:9tai22$1fok$1@digitaldaemon.com...
> From The D Programming Language, arrays section:  Is this last bit about
b
> = a[0 .. a.length]  true, or should it actually be  b = a[0 .. a.length-1]

a[0..a.length] is it.


November 19, 2001
8-0

This is a Bad Thing, IMHO.  The .length property should give the *length* of the array, not the maximum index!  You could add a maximum index property, though:

b = a[0..a.length-1];  // ok
b = a[0..a.length];  // ArrayOutOfBoundsException
b = a[0..a.maxIndex]; // ok

Or, perhaps better yet, you could just allow unbounded slicing, which goes to the edges:

b = a[0..];
b = a[..a.maxIndex];
b = a[..]; // all 3 of these are identical



Walter wrote:

> "Sean L. Palmer" <spalmer@iname.com> wrote in message news:9tai22$1fok$1@digitaldaemon.com...
> > From The D Programming Language, arrays section:  Is this last bit about
> b
> > = a[0 .. a.length]  true, or should it actually be  b = a[0 .. a.length-1]
>
> a[0..a.length] is it.

--
The Villagers are Online! 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))) ]


November 20, 2001
But the length is not the maximum index.

"Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3BF94B93.6D0C72FF@deming-os.org...
> 8-0
>
> This is a Bad Thing, IMHO.  The .length property should give the *length*
of the
> array, not the maximum index!  You could add a maximum index property,
though:
>
> b = a[0..a.length-1];  // ok
> b = a[0..a.length];  // ArrayOutOfBoundsException
> b = a[0..a.maxIndex]; // ok
>
> Or, perhaps better yet, you could just allow unbounded slicing, which goes
to
> the edges:
>
> b = a[0..];
> b = a[..a.maxIndex];
> b = a[..]; // all 3 of these are identical
>
>
>
> Walter wrote:
>
> > "Sean L. Palmer" <spalmer@iname.com> wrote in message news:9tai22$1fok$1@digitaldaemon.com...
> > > From The D Programming Language, arrays section:  Is this last bit
about
> > b
> > > = a[0 .. a.length]  true, or should it actually be  b = a[0 ..
a.length-1]
> >
> > a[0..a.length] is it.
>
> --
> The Villagers are Online! 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))) ]
>
>


November 20, 2001
"Pavel Minayev" <evilone@omen.ru> wrote in message news:9tbc2a$1vm1$1@digitaldaemon.com...
> "Sean L. Palmer" <spalmer@iname.com> wrote in message news:9tai22$1fok$1@digitaldaemon.com...
> > From The D Programming Language, arrays section:  Is this last bit about
> b
> > = a[0 .. a.length]  true, or should it actually be  b = a[0 ..
a.length-1]
> > ?   In other words, are ranges inclusive, or not?
>
>     "s[0..4] = ...  // error, only 3 elements in s"
>
> So ranges are inclusive, and you get an exception if
> you write s[0..s.length].

s[0..4] has 4 elements: s[0], s[1], s[2], s[3]


November 20, 2001

Walter wrote:
> 
> s[0..4] has 4 elements: s[0], s[1], s[2], s[3]

So array-slice ranges are half-open, yes? Your first slice example in the spec says:

	b = a[1..3];	a[1..3] is a 3 element array consisting of
			a[1], a[2], and a[3]


Should this read "a 2 element array consisting of a[1] and a[2]"?

This kind of ranging is going to piss off C programmers; this thread being case in point.

-RB
November 20, 2001
"Russell Borogove" <kaleja@estarcion.com> wrote in message news:3BF9CD48.E638FD8@estarcion.com...
>
>
> Walter wrote:
> >
> > s[0..4] has 4 elements: s[0], s[1], s[2], s[3]
>
> So array-slice ranges are half-open, yes? Your first slice example in the spec says:
>
> b = a[1..3]; a[1..3] is a 3 element array consisting of a[1], a[2], and a[3]

Looks like the spec is wrong <g>.

> This kind of ranging is going to piss off C programmers; this thread being case in point.

First I have to get the documentation right.



November 20, 2001
"Walter" <walter@digitalmars.com> wrote in message news:9tche0$2n2v$3@digitaldaemon.com...

> But the length is not the maximum index.

Then [0..length] is not legal.


November 20, 2001
"Pavel Minayev" <evilone@omen.ru> wrote in message news:9tcv3f$2vca$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:9tche0$2n2v$3@digitaldaemon.com...
>
> > But the length is not the maximum index.
>
> Then [0..length] is not legal.

I don't understand what you're driving at, then.


« First   ‹ Prev
1 2 3 4 5 6 7