<br><br><div class="gmail_quote">On Fri, Aug 6, 2010 at 19:41, bearophile <span dir="ltr"><<a href="mailto:bearophileHUGS@lycos.com">bearophileHUGS@lycos.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Philippe Sigaud:<br>
<div class="im">> Here is what I cooked, it's still a bit rough around the edges. It has an<br>
> optional step argument, to see how many elements to jump.<br>
<br>
</div>It's better to give it a default chunk size of 2.<br></blockquote><div><br>Why?<br>And what should the default step be, according to you? If chose n (the chunk size), because that's want the OP wanted.<br> <br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
If I have understood this well, then this is the partition() function:<br>
<a href="http://reference.wolfram.com/mathematica/ref/Partition.html" target="_blank">http://reference.wolfram.com/mathematica/ref/Partition.html</a><br></blockquote><div><br>Yeah, partition, chunk, segment, it a basic thing, worth including in std.range.<br>
Very useful in conjunction with mapping: calculating the moving average, for example.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
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]. </blockquote>
<div><br>This simple code does this already: chunks(range, 2, 1).<br> <br></div></div><br>