On Monday, 25 May 2015 at 23:14:39 UTC, Vlad Levenfeld wrote:
And I think that the symbol `ℕ` in your code you need to replace some words.

Ok, done.

Your `cycle` - this is a very great and interesting idea!

It is necessary to implement such a foreach:

import std.algorithm : equal;

void main() {

auto matrix = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], [[10, 11, 12]]];

        foreach (idx, i, j, k..., el; matrix) {
assert(equal(el[0], [1, 2, 3]); // el[1] == [4, 5, 6], el [2] == [7, 8, 9] el[3] == [10, 11, 12]
                assert(equal(i[0], 1)); // i[1] == 2, i[2] == 3, i[3] == 3
                assert(equal(j[0], 4)); // k[1] == 5, k[2] == 6
                // idx == 0 .. matrix.length
        }
}

Of course, this is just an idea. We need to think of something more general and better than my stub code. Ie create an array of iterators for each subarray. It may sound funny, but you can create a new foreach with advanced features for the n-dimensional arrays.


Also, for the n-dimensional arrays are important new advanced input methods, such as in Python, something like:

auto a = [[readln.split.map!(to!int)], [readln.split.map!(to!int)]];

// writeln(a); // [[[4, 5, 6, 3, 1, 5, 6]], [[4, 8, 6, 5, 6, 2, 9]]] // map

writeln(a); // [[4, 5, 6, 3, 1, 5, 6]], [[4, 8, 6, 5, 6, 2, 9]] // without map

Ie you need to create aliases for this, for example, readlnArrayInt/readlnArrayStr/etc. And to finalize these input methods for correct and more convenient work with n-dimensional arrays.

Reply via email to