digitalmars.D - Auto Interation
- janderson (13/13) Sep 01 2007 Here's a random idea that I think may be a little bit much:
- Bill Baxter (5/26) Sep 01 2007 That's what the function called 'apply' typically does in the functional...
- janderson (4/32) Sep 01 2007 Some other languages I've use have a foreach function in the standard
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.
Sep 01 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
Sep 01 2007
Bill Baxter wrote:janderson wrote:Some other languages I've use have a foreach function in the standard lib. However the point is those can't be overridden. -JoelHere'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
Sep 01 2007