I have a suggestion.
janderson
askme at me.com
Wed May 16 19:24:06 PDT 2007
Oskar Linde wrote:
> 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
I agree. I still don't understand why the compiler can't have a special
inbuilt reverse keyword as an attribute of arrays, that it can optimize
away when it needs to.
-Joel
More information about the Digitalmars-d-announce
mailing list