Auto Interation

janderson askme at me.com
Sat Sep 1 03:10:29 PDT 2007


Bill Baxter wrote:
> janderson wrote:
>> Here's a random idea that I think may be a little bit much:
>>
>> Auto Array iteration.
>>
>> If you have a function like:
>>
>> void foo(int x);
>>
>> Then the language could allow you to use it on arrays like:
>>
>> auto array = new int[];
>> foo(array);  //Iterate though every array
>> foo(5);  //One element like normal
>>
>> foo(int[] x);  //Override array version of the operation to do 
>> something more optimal.
>>
>> It may make logic errors more difficult to see, so scratch that idea.
>>
>> Perhaps it could be done with some template syntax in a slightly more 
>> verbose way.
> 
> That's what the function called 'apply' typically does in the functional 
> paradigm.  Something like  apply(foo, array).  With the extended member 
> syntax proposed you could even make it be   foo.apply(array).
> 
> --bb

Some other languages I've use have a foreach function in the standard 
lib.  However the point is those can't be overridden.

-Joel



More information about the Digitalmars-d mailing list