std.multidimarray

Dennis Ritchie via Digitalmars-d digitalmars-d at puremagic.com
Mon May 25 17:02:10 PDT 2015


On Monday, 25 May 2015 at 23:40:46 UTC, Vlad Levenfeld wrote:
> I don't mean nested arrays, I mean an equivalent recursive 
> definition for the sake of exposing a "natural" traversal 
> strategy, which you get if your object admits the notion of a 
> pointed element and of proper disjoint subobjects. For example:
>
> T[0..$] = {T[0], T[1..$]}
>
> T[0..$, 0..$]
>   = {T[0, 0..$], T[1..$, 0..$]}
>   = {{T[0, 0], T[0, 1..$]}, T[1..$, 0..$]}
>
> And so on. The second definition is just lexicographic 
> traversal expressed in recursive language.
>
> If there were a way to write an adaptor to deduce such a 
> recursive definition and then present it as an input range, you 
> could have a uniform syntax for iterating over 
> differently-shaped data structures.
>
> The problem that I run into is presenting this as an input 
> range for foreach. "front" obviously refers to the pointed 
> element, but "popFront" typically returns void, not a smaller 
> instance of the object - which means things like trees and 
> multidim arrays need to eschew "front/popFront/empty" in favor 
> of something like "head/tails[]" (with tails[].empty == true 
> being the termination condition), but this isn't a viable 
> solution for foreach loops.
>
> I'm writing this in a bit of a hurry so I might be missing 
> something essential but this is more or less the conclusion 
> that I've reached after spending the last few months thinking 
> about the problem. Fresh ideas are very welcome.

The system of disjoint sets and D-ranges. Sounds great! I think 
about what ideas can be offered. The idea is very good!


More information about the Digitalmars-d mailing list