<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">While working with mgcollections.set, Jameson and I noticed a curiosity.<div><br></div><div>If you have a method </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span><i>withAll</i>(items:Collection<Dynamic>) </div><div><br></div><div>and you want to write a method </div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span><i>with</i>(*items:Dynamic)</div><div><br></div><div>then it's easy:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>method <i>with</i>(*items:Dynamic) { self.<i>withAll</i>(items) }</div><div><br></div><div>On the other hand, if you have <i>with</i>(), and want to write <i>withAll</i>(), then there is no way to do it without using reflection. Even then, the code is messy; this was what I came up with:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>method <i>withAll</i>(items:Collection<Dynamic>) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>def selfMirror = mirror.<i>reflect</i>(self)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>def argLists = list.<i>with</i>(items)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>def withMethod = selfMirror.<i>forMethod</i> "with"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>withMethod.<i>request</i>(argLists)</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div>The moral of the story, I think, is that we should make it a practice in defining library interfaces never to define a variable arity method directly, but instead to always define a method that takes an array of arguments, and then to define the varArity method in terms of that (as I did above for method "with"). Notice that the bodies of <i>withAll</i> and <i>with</i> are identical: in both cases, <i>items</i> is a Collection.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Andrew</div><div> </div></body></html>