Jump to page: 1 26  
Page
Thread overview
foreach_reverse is better than ever
Feb 14, 2010
Jonathan M Davis
Feb 14, 2010
Jacob Carlborg
Feb 14, 2010
Michel Fortin
Feb 14, 2010
bearophile
Feb 14, 2010
Michel Fortin
Feb 14, 2010
Leandro Lucarella
Feb 14, 2010
Mike James
Feb 14, 2010
bearophile
Feb 14, 2010
bearophile
Feb 14, 2010
Justin Johansson
Feb 14, 2010
Adam D. Ruppe
Feb 14, 2010
Nick Sabalausky
Feb 14, 2010
Igor Lesik
Feb 14, 2010
Nick Sabalausky
Feb 15, 2010
retard
Feb 15, 2010
Leandro Lucarella
Feb 16, 2010
KennyTM~
Feb 14, 2010
Mike James
Feb 14, 2010
Nick Sabalausky
Feb 14, 2010
Mike James
Feb 14, 2010
Justin Johansson
Feb 14, 2010
Ary Borenszweig
Feb 15, 2010
retard
Feb 15, 2010
Ary Borenszweig
Feb 15, 2010
Leandro Lucarella
Feb 15, 2010
Michel Fortin
Feb 15, 2010
Jacob Carlborg
Feb 15, 2010
Jonathan M Davis
Feb 15, 2010
Michel Fortin
Feb 15, 2010
dsimcha
Feb 15, 2010
bearophile
Feb 15, 2010
Justin Johansson
Feb 15, 2010
Pelle Månsson
Feb 16, 2010
Yigal Chripun
Feb 15, 2010
Leandro Lucarella
Feb 16, 2010
Yigal Chripun
Feb 15, 2010
torhu
Feb 14, 2010
Daniel Murphy
Feb 14, 2010
bearophile
Feb 14, 2010
bearophile
Feb 14, 2010
Michel Fortin
Feb 14, 2010
dsimcha
Feb 14, 2010
dsimcha
Feb 14, 2010
grauzone
Feb 14, 2010
dsimcha
Feb 14, 2010
Mike James
Feb 14, 2010
Bane
February 14, 2010
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
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
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
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
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
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
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
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
> The foreach(i; 1 .. 100 : -1)

Sorry, I meant:
foreach(i; 99 .. 0 : -1)

Bye,
bearophile
February 14, 2010
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/

« First   ‹ Prev
1 2 3 4 5 6