range chunks

bearophile bearophileHUGS at lycos.com
Fri Aug 6 10:41:57 PDT 2010


Philippe Sigaud:
> Here is what I cooked, it's still a bit rough around the edges. It has an
> optional step argument, to see how many elements to jump.

It's better to give it a default chunk size of 2.
If I have understood this well, then this is the partition() function:
http://reference.wolfram.com/mathematica/ref/Partition.html

If you want to be more complete you can add two more features: to start counting items from the end (but they are given from the start) and give a "duplication window", so for example the natural numbers with a window of 2 and a duplication of 1 are [1, 2], [2, 3], [3, 4]. But adding too many features risks to produce functions like the Mathematica ones, that sometimes are hard to use because they have tons of complex arguments.)

Bye,
bearophile


More information about the Digitalmars-d mailing list