Thread overview | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 09, 2006 Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
I'm learning ruby right now, and I noticed they use a very cool syntax for ranges. 0..5 means 0, 1, 2, 3, 4, 5 0...5 means 0, 1, 2, 3, 4 The current array slicing is useful half the time and a pain in the arse the other half, so I was wondering if anyone else has mentioned this idea for D before... - Trevor |
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to %u | %u wrote:
> I'm learning ruby right now, and I noticed they use a very cool syntax for ranges.
>
> 0..5 means 0, 1, 2, 3, 4, 5
> 0...5 means 0, 1, 2, 3, 4
>
> The current array slicing is useful half the time and a pain in the arse the
> other half, so I was wondering if anyone else has mentioned this idea for D
> before...
I have a bit of a problem with .. vs ..., I think they both look too similar making it hard to review code for correctness, and I'd have a hard time remembering which means which, another source of bugs.
|
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to %u | %u wrote:
> I'm learning ruby right now, and I noticed they use a very cool syntax for ranges.
>
> 0..5 means 0, 1, 2, 3, 4, 5
> 0...5 means 0, 1, 2, 3, 4
>
> The current array slicing is useful half the time and a pain in the arse the
> other half, so I was wondering if anyone else has mentioned this idea for D
> before...
>
> - Trevor
in python you have a slice object, which you can pass like you would pass a range, works beautifully, is more powerful and in my eyes less error prone than .. or ... and I think ruby must change it <g> because ... has one point more than .. but one element less ... (these latest 3 points indicate I could go on and on ... :-) )
roel
|
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | I'd really like to have a distinction between exclusive and inclusive slicing. Maybe '..'(inclusive) and '..-'(exclusive) or similar, with '..' => '..-'. Not *that* beautiful, though .. maybe someone has a better suggestion.
Alex
Walter Bright wrote:
> %u wrote:
>> I'm learning ruby right now, and I noticed they use a very cool syntax for ranges.
>>
>> 0..5 means 0, 1, 2, 3, 4, 5
>> 0...5 means 0, 1, 2, 3, 4
>>
>> The current array slicing is useful half the time and a pain in the arse the
>> other half, so I was wondering if anyone else has mentioned this idea for D
>> before...
>
> I have a bit of a problem with .. vs ..., I think they both look too similar making it hard to review code for correctness, and I'd have a hard time remembering which means which, another source of bugs.
|
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | == Quote from Walter Bright (newshound@digitalmars.com)'s article
> I have a bit of a problem with .. vs ..., I think they both look too similar making it hard to review code for correctness, and I'd have a hard time remembering which means which, another source of bugs.
That kind of error wouldn't compile, I think...
Oh. I see what your saying. I didn't even notice the two examples were different.
I haven't ever had trouble with the current slice syntax.
|
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to rm | rm wrote: > %u wrote: >> I'm learning ruby right now, and I noticed they use a very cool syntax for ranges. >> >> 0..5 means 0, 1, 2, 3, 4, 5 >> 0...5 means 0, 1, 2, 3, 4 >> > and I think ruby must change it <g> because ... has one point more than .. but one element less ... (these latest 3 points indicate I could go on and on ... :-) ) > Whoa! I skimmed the ruby docs about .. vs ... a while back and I remember thinking "hey that's really cool, and easy to remember too because ... goes farther than .." I guess it was just so obvious to me that that would be their meaning that I didn't realize that Ruby had it backwards. Plus non-inclusive is generally more used in programming languages with 0-based indexing. The shorter thing should be the more common. It made total sense to me. But I was wrong. Ouch. Ruby really flubbed that one. Well D certainly won't make that mistake, because .. is already too entrenched as non-inclusive. :-) --bb |
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | == Quote from Walter Bright (newshound@digitalmars.com)'s article
> I have a bit of a problem with .. vs ..., I think they both look too similar making it hard to review code for correctness, and I'd have a hard time remembering which means which, another source of bugs.
Perhaps you guys aren't keen on the .. and ...
But it would be nice to have some symbol mean "through" in ranges to acompany the current .. which means "until"
Like..
0 _ 5 == 0, 1, 2, 3, 4, 5
0 .. 5 == 0, 1, 2, 3, 4
Sorry - I know there's more important things to do.... Just puting my 2 cents in...
|
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trevor Parscal | Trevor Parscal wrote:
> == Quote from Walter Bright (newshound@digitalmars.com)'s article
>> I have a bit of a problem with .. vs ..., I think they both look too
>> similar making it hard to review code for correctness, and I'd have a
>> hard time remembering which means which, another source of bugs.
>
> Perhaps you guys aren't keen on the .. and ...
>
> But it would be nice to have some symbol mean "through" in ranges to acompany the
> current .. which means "until"
>
> Like..
>
> 0 _ 5 == 0, 1, 2, 3, 4, 5
> 0 .. 5 == 0, 1, 2, 3, 4
>
> Sorry - I know there's more important things to do.... Just puting my 2 cents in...
__ is a legal identifier though, so you'd need spaces to use it generally.
Maybe
arr[2~~3] -- two dots stretch out and squgglified?
arr[2**2] -- two dots gone hairy?
arr[2::3] -- two dots .. on top of two dots ..
arr[2``3] -- closest you can get to two dots up high
arr[2##3] -- eh..
arr[N@@B] -- heh heh
Or how just put it all together: arr[2`~.@#:3]
--bb
|
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | > Maybe > > arr[2~~3] -- two dots stretch out and squgglified? > arr[2**2] -- two dots gone hairy? > arr[2::3] -- two dots .. on top of two dots .. > arr[2``3] -- closest you can get to two dots up high > arr[2##3] -- eh.. > arr[N@@B] -- heh heh > I noticed that ~~ is listed as a token on the Lexical page (http://www.digitalmars.com/d/lex.html), but I can't find reference to it anywhere else. What is ~~ used for? |
November 09, 2006 Re: Array Slice Ranges | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | == Quote from Bill Baxter (dnewsgroup@billbaxter.com)'s article
> __ is a legal identifier though, so you'd need spaces to use it generally.
> Maybe
> arr[2~~3] -- two dots stretch out and squgglified?
> arr[2**2] -- two dots gone hairy?
> arr[2::3] -- two dots .. on top of two dots ..
> arr[2``3] -- closest you can get to two dots up high
> arr[2##3] -- eh..
> arr[N@@B] -- heh heh
> Or how just put it all together: arr[2`~.@#:3]
> --bb
Yes, arr[2`~.@#:3] does look pretty clean....
I see what you mean about _ being a legal identifier...
Perhaps arr[0 .-. 5] ?
Forget it.. I know there's no chance in hell this is gonna get added to the language even if magically a new symbol was made on everyone's keyboards that meant THROUGH but wasnt a - and had no other use except this specific purpose....
But I'm not angry about this, so long as walter continues working on D and doesnt retire in Florida and throw his computer away I'm happy.
|
Copyright © 1999-2021 by the D Language Foundation