Auto Interation

Bill Baxter dnewsgroup at billbaxter.com
Sat Sep 1 00:40:19 PDT 2007


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



More information about the Digitalmars-d mailing list