February 14, 2010 foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Gone, that is. Walter agreed to remove it. To achieve the functionality of foreach_reverse (r) { ... } use foreach (retro(r)) { ... } using retro in std.range. Andrei |
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> Gone, that is. Walter agreed to remove it.
>
> To achieve the functionality of
>
> foreach_reverse (r) { ... }
>
> use
>
> foreach (retro(r)) { ... }
>
> using retro in std.range.
>
>
> Andrei
I assume that this was to get rid of a keyword and reduce duplicate functionality.
Though I must say that I find retro to be a bit funny. I would have expected it to be reverse. It would be clearer, I think, but it's not like it's hard to find out what retro does and remember it.
- Jonathan M Davis
|
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu Wrote:
> Gone, that is. Walter agreed to remove it.
>
> To achieve the functionality of
>
> foreach_reverse (r) { ... }
>
> use
>
> foreach (retro(r)) { ... }
>
> using retro in std.range.
>
>
> Andrei
What about where foreach is being done over something other than a range?
eg.
foreach(i; 1..100)
foreach(v; structwithopapply)
|
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 2/14/10 09:14, Jonathan M Davis wrote:
> Andrei Alexandrescu wrote:
>
>> Gone, that is. Walter agreed to remove it.
>>
>> To achieve the functionality of
>>
>> foreach_reverse (r) { ... }
>>
>> use
>>
>> foreach (retro(r)) { ... }
>>
>> using retro in std.range.
>>
>>
>> Andrei
>
> I assume that this was to get rid of a keyword and reduce duplicate
> functionality.
>
> Though I must say that I find retro to be a bit funny. I would have expected
> it to be reverse. It would be clearer, I think, but it's not like it's hard
> to find out what retro does and remember it.
>
> - Jonathan M Davis
It iterates backwards, all the way back to the 50s. I think "reverse" is a much better word.
/Jacob Carlborg
|
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> Gone, that is. Walter agreed to remove it.
>
> To achieve the functionality of
>
> foreach_reverse (r) { ... }
>
> use
>
> foreach (retro(r)) { ... }
>
> using retro in std.range.
Let me first say that I think it's great that one of D's ugliest keywords is going away. But does retro (or ranges in general) support iteration over both index and element?
foreach_reverse(i, e; foo) { ... }
-Lars
|
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars T. Kyllingstad | Lars T. Kyllingstad wrote: > Andrei Alexandrescu wrote: >> Gone, that is. Walter agreed to remove it. >> >> To achieve the functionality of >> >> foreach_reverse (r) { ... } >> >> use >> >> foreach (retro(r)) { ... } >> >> using retro in std.range. Now all what's left to do is to make it as efficient as the builtin functionality. > > Let me first say that I think it's great that one of D's ugliest keywords is going away. But does retro (or ranges in general) support iteration over both index and element? > > foreach_reverse(i, e; foo) { ... } And will it be able to parse utf-8 backwards? I assume proper utf-8 support with ranges (or whatever is planned) isn't implemented yet, so I didn't test it. > -Lars |
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu Wrote:
> Gone, that is. Walter agreed to remove it.
>
> To achieve the functionality of
>
> foreach_reverse (r) { ... }
>
> use
>
> foreach (retro(r)) { ... }
>
> using retro in std.range.
>
>
> Andrei
I think Reverse would have been a better title. Retro sounds like you might be using only 8088 assembler instructions in the output...
-=mike=-
|
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Murphy | Daniel Murphy: > What about where foreach is being done over something other than a range? > eg. > foreach(i; 1..100) > foreach(v; structwithopapply) The first can be done turning an interval into syntax sugar for iota(1,100): The foreach(i; retro(1 .. 100)) Otherwise the interval syntax can grow the step, as in Python and other languages (in D the step might even be a compile-time constant): The foreach(i; 1 .. 100 : -1) The second gives no problems if retro is well done: foreach(v; retro(structWithopApplyReverse)) Bye, bearophile |
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > The foreach(i; 1 .. 100 : -1)
Sorry, I meant:
foreach(i; 99 .. 0 : -1)
Bye,
bearophile
|
February 14, 2010 Re: foreach_reverse is better than ever | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 2010-02-14 05:12:41 -0500, Jacob Carlborg <doob@me.com> said: > It iterates backwards, all the way back to the 50s. I think "reverse" is a much better word. Agree. My dictionary says: "retro": imitative of a style, fashion, or design from the recent past. It's an amusing name in the way Andrei likes it, but the meaning isn't very clear. "reverse" would be a better name. -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ |
Copyright © 1999-2021 by the D Language Foundation