<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 30 Jul 2013, at 10:25, James Noble wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Calibri; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><blockquote type="cite">They are three different things, so shouldn't they have three different methods?<span class="Apple-converted-space"> </span><br></blockquote><br>I guess that's the question, isn't it? This is why API design is hard and how language design interacts with API design. <br></div></span></blockquote><div><br></div>API design for experts and API design for novices have different goals. For novices, offering guidance and catching mistakes is the most important, I think. For experts, it may be "power" and universality.<br><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Calibri; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><br><blockquote type="cite">repeat(n)times(zeroaryblock)<br></blockquote><blockquote type="cite">for(vals)do(unaryBlock)<br></blockquote><blockquote type="cite">withValIndex(vals)do(binaryBlock)</blockquote></div></span></blockquote></div><br><div><br></div><div>Why not:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>theCollection.do { each -> stuff }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>theArray.doWithIndex { each, ix -> stuff }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>4.timesRepeat { stuff }</div><div><br></div><div>What's the value of adding dialect-level methods so that </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>repeat (n) times { stuff } </div><div>and</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>for (theArray) doWithIndex { each, ix -> stuff }</div><div><br></div><div>gets turned into </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>n.timesRepeat {stuff}</div><div>and</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>theArray.doWithIndex { each, ix -> stuff } ?</div><div><br></div><div>It's just one more level of syntax to explain—students will need to learn to read the collection APIs themselves. Will this syntax help when the student transfers to a language with C-like syntax for for loops? Not one whit.</div><div><br></div><div>Most valuable to the learner is systematic naming within our own APIs. Which means that we can't just carry stuff over from some other language: we have to de-design.</div><div><br></div><div>The "iter" objects that Michael put in the libraries are useful when one needs multiple streams, coming from multiple collections (as, for example, when implementing a merge). They are overkill for implementing do, which can be done with a single method. In contrast, thinking about error checking, putting some "fail fast" logic into iterators, as does Java, to detect modification of the underlying collection, might be really valuable for novices.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Andrew</div><div><br></div><div><br></div><div><br></div><div><br></div></body></html>