Jump to page: 1 2 3
Thread overview
I have a suggestion.
May 16, 2007
YonggangLuo
May 16, 2007
freeagle
May 16, 2007
Pragma
May 16, 2007
Ary Manzana
May 16, 2007
antonio
May 16, 2007
BCS
May 16, 2007
Oskar Linde
May 17, 2007
janderson
May 17, 2007
Dave
May 16, 2007
Brian Byrne
May 16, 2007
renoX
May 16, 2007
Bill Baxter
May 16, 2007
Brian Byrne
May 17, 2007
janderson
May 17, 2007
Bastiaan Veelo
May 17, 2007
Anders Bergh
May 16, 2007
Mikola Lysenko
Ideas for shortening "foreach_reverse" (was Re: I have a suggestion.)
May 17, 2007
Justin C Calvarese
May 17, 2007
Sean Kelly
May 17, 2007
Bill Baxter
May 18, 2007
Derek Parnell
May 18, 2007
Pragma
May 18, 2007
Charles D Hixson
May 17, 2007
Jb
May 16, 2007
i think it's will be a good idea to replace "foreach_reverse" with  "frr". "foreach_reverse" is too long as a keyword
May 16, 2007
YonggangLuo wrote:
> i think it's will be a good idea to replace "foreach_reverse" with  "frr".
> "foreach_reverse" is too long as a keyword

I find "frr" very cryptic.

consider this:

if(reverse)
{
	frr(int i, array)
	{
		...
	}
}
else
{
	foreach(int i, array)
	{
		...
	}
}

Those keywords doesn't seem related, but would in fact provide similar funcitonality.

I too would like to see this "foreach_reverse" solved in other way, but not with another keyword

freeagle
May 16, 2007
freeagle wrote:
> YonggangLuo wrote:
>> i think it's will be a good idea to replace "foreach_reverse" with  "frr".
>> "foreach_reverse" is too long as a keyword
> 
> I find "frr" very cryptic.
> 
> consider this:
> 
> if(reverse)
> {
>     frr(int i, array)
>     {
>         ...
>     }
> }
> else
> {
>     foreach(int i, array)
>     {
>         ...
>     }
> }
> 
> Those keywords doesn't seem related, but would in fact provide similar funcitonality.
> 
> I too would like to see this "foreach_reverse" solved in other way, but not with another keyword
> 
> freeagle

I agree with you completely.  While I understand the goal behind "foreach_reverse" is to put optimal array-traversal-loop generation in the hands of the compiler (read: faster than opApply), the keyword itself remains the only real wart.  The keyword "rforeach" would have made a much better candidate IMO.

-- 
- EricAnderton at yahoo
May 16, 2007
I do like foreach_reverse. It's a very explicity name, and it doesn't appear often. And I guess an editor could provide a template for it, so just typing "fore" and pressing the down arrow will be enough.

Pragma escribió:
> freeagle wrote:
>> YonggangLuo wrote:
>>> i think it's will be a good idea to replace "foreach_reverse" with  "frr".
>>> "foreach_reverse" is too long as a keyword
>>
>> I find "frr" very cryptic.
>>
>> consider this:
>>
>> if(reverse)
>> {
>>     frr(int i, array)
>>     {
>>         ...
>>     }
>> }
>> else
>> {
>>     foreach(int i, array)
>>     {
>>         ...
>>     }
>> }
>>
>> Those keywords doesn't seem related, but would in fact provide similar funcitonality.
>>
>> I too would like to see this "foreach_reverse" solved in other way, but not with another keyword
>>
>> freeagle
> 
> I agree with you completely.  While I understand the goal behind "foreach_reverse" is to put optimal array-traversal-loop generation in the hands of the compiler (read: faster than opApply), the keyword itself remains the only real wart.  The keyword "rforeach" would have made a much better candidate IMO.
> 
May 16, 2007
YonggangLuo wrote:
> i think it's will be a good idea to replace "foreach_reverse" with  "frr".
> "foreach_reverse" is too long as a keyword

I tend to side on being explicit, so I don't think "frr" would be that great of a name change. But I will agree that foreach_reverse looks fairly ugly (more than a keyword should).

Anyways, along your lines I think "fer" (ForEachReverse) would be a more appropriate abbreviation. I can give it association to hillbilly speech, "Fer dat dem dere list [insert mental image of a scraggly old man in overalls holding a list upside-down]..."

More seriously, I think a better keyword would be rforeach, revforeach, or something similarly parallel. Something about reading underscores in keywords (*cough* C++) makes me cringe at the sight.

Brian Byrne
May 16, 2007
Pragma wrote:
> freeagle wrote:
>> YonggangLuo wrote:
>>> i think it's will be a good idea to replace "foreach_reverse" with  "frr".
>>> "foreach_reverse" is too long as a keyword
>>
>> I find "frr" very cryptic.
>>
>> consider this:
>>
>> if(reverse)
>> {
>>     frr(int i, array)
>>     {
>>         ...
>>     }
>> }
>> else
>> {
>>     foreach(int i, array)
>>     {
>>         ...
>>     }
>> }
>>
>> Those keywords doesn't seem related, but would in fact provide similar funcitonality.
>>
>> I too would like to see this "foreach_reverse" solved in other way, but not with another keyword
>>
>> freeagle
> 
> I agree with you completely.  While I understand the goal behind "foreach_reverse" is to put optimal array-traversal-loop generation in the hands of the compiler (read: faster than opApply), the keyword itself remains the only real wart.  The keyword "rforeach" would have made a much better candidate IMO.
> 
I think the more "algebraic" way could be something like

foreach(int i; reversed array)

compiler must act in the optimal way.



May 16, 2007
antonio wrote:
> I think the more "algebraic" way could be something like
> 
> foreach(int i; reversed array)
> 
> compiler must act in the optimal way.
> 

or we could take a hint from scope and do:

foreach(reverse)(i;arr)

that leaves the door open for things like

foreach(stride, 5)(i;arr) {}

and

foreach(heaptree)(i;arr) {}

the overloads could be something like

opApply(char[] : "reverse")(int delegate(inout int));

May 16, 2007
YonggangLuo Wrote:

> i think it's will be a good idea to replace "foreach_reverse" with  "frr". "foreach_reverse" is too long as a keyword


I like this idea, but "frr" is downright inconsistent with the rest of the language.  What if we do something like this:

~foreach( x; arr )

While reducing keystrokes, recycling a unary operator also cuts down keyword bloat.  My only concern is that it might be too subtle.  I suspect that for non-English users, there would be few tears shed over the death of "foreach_reverse."

Ultimately, the best option might be to do as Tom S. and others have suggested and simply axe it entirely.  Using a clever template you could actually implement a very efficient reverse foreach within the standard library.

-Mik
May 16, 2007
Brian Byrne a écrit :
> More seriously, I think a better keyword would be rforeach, revforeach, or something similarly parallel. Something about reading underscores in keywords (*cough* C++) makes me cringe at the sight.
> 
> Brian Byrne

While_a_shorter_keyword_could_be_better_whats_wrong_with_underscores?

BasicallyThereAreTwoChoiceToLinkSeveralWordsTogetherEitherUnderscoreOrUsingCase.

Guess which one is easier one the eye with the two above sentence?

I *really* don't understand those who prefer CamelCase, it's harder to read, it doesn't work well with shortcuts such as IBM, etc, the only good point of CamelCase is that it is a little more compact, bah.

renoX
May 16, 2007
BCS skrev:
> antonio wrote:
>> I think the more "algebraic" way could be something like
>>
>> foreach(int i; reversed array)
>>
>> compiler must act in the optimal way.
>>
> 
> or we could take a hint from scope and do:
> 
> foreach(reverse)(i;arr)
> 
> that leaves the door open for things like
> 
> foreach(stride, 5)(i;arr) {}
> 
> and
> 
> foreach(heaptree)(i;arr) {}
> 
> the overloads could be something like
> 
> opApply(char[] : "reverse")(int delegate(inout int));
> 

Not that I havn't said it before, but there doesn't need to be any language changes at all. Removing foreach_reverse altogether doesn't remove any expressiveness -- just a special case.

If the compiler was smart enough to 1) be able to inline functions with loops, and 2) be able to inline const (at compile time known) delegate calls (which it possibly does already), there would be no need for this special case keyword.

foreach(i; arr), foreach(i; reverse(arr)), foreach(i; heaptree(arr)), and so on, could all be equally efficient.

/Oskar
« First   ‹ Prev
1 2 3