// So why shouldn't this work?
auto range = 0..10;
foreach (i; range) doScience(i);

Replace the first line with:

        auto range = iota(0, 10);

and it will work. It's not *that* hard to learn, is it?

True, but I think the issue at hand when discussing "sugary" syntax is clarity and expressiveness rather than completeness. In many domains, programmer working memory is at a premium, and code like this:
{
auto samples = meshgrid(iota(0, 2), iota(0, 100), iota(0, 100));
    vector[StridedSlice(0, 10, 2)] = iota(1, 6);
    plot(iota(-10, 10), myFunction(iota(-10, 10)));
    foreach (i; square(iota(0, 10))) performSquareDance(i);
}
might not be as respectful of that resource as code like this:
{
    auto samples = meshgrid(0..2, 0..100, 0..100);
    vector[(0..10).by(2)] = 1..6;
    plot(-10..10, myFunction(-10..10));
    foreach (i; square(0..10)) performSquareDance(i);
}

Reference for `meshgrid`:
http://www.mathworks.com/help/matlab/ref/meshgrid.html

Reference for strided indexing:
http://docs.scipy.org/doc/numpy/user/basics.indexing.html

On Friday, 14 March 2014 at 14:36:29 UTC, H. S. Teoh wrote:
On Fri, Mar 14, 2014 at 12:29:34PM +0000, bearophile wrote:
Mason McGill:

>My concern is that this design may be ignoring some of the >lessons
>the SciPy community has learned over the past 10+ years.

Thank you for your help. An injection of experience is quite
important here. Julia is far newer than D, and yet it has already a
better design and more refined implementation in several things
related to numerical computing.


>// So why shouldn't this work?
>auto range = 0..10;
>foreach (i; range) doScience(i);

People have suggested this lot of time ago, again and again. So I
ask that question for Walter.
[...]

Replace the first line with:

        auto range = iota(0, 10);

and it will work. It's not *that* hard to learn, is it?


T

Reply via email to