<div dir="ltr">Hi Ben,<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 1, 2013 at 7:01 AM, Benjamin <span dir="ltr">&lt;<a href="mailto:Benjamin.VanRyseghem.Pharo@gmail.com" target="_blank">Benjamin.VanRyseghem.Pharo@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello guys,<div><br></div><div>is it expected that</div><div><br></div><div>1 perform: #gcd: withArguments: {2} </div>
<div>works</div><div><br></div><div>while</div><div><br></div><div>1 perform: #gcd: withArguments: {2} asOrderedCollection</div><div><div>
fails ?</div></div></div></blockquote><div><br></div><div>As Alexandre explained it&#39;s because the VM insists on an Array.  But there is a neat way to solve this.  e.g. if the method is defined as</div><div><br></div>
<div>Object&gt;&gt;perform: selector withArguments: argArray </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Send the selector, aSymbol, to the receiver with arguments in argArray.</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>Fail if the number of arguments expected by the selector </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>does not match the size of argArray.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>Primitive. Optional. See Object documentation whatIsAPrimitive.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 84&gt;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>^ self perform: selector withArguments: argArray inSuperclass: self class</div><div><br></div><div> and</div><div><div><br></div><div>Object&gt;&gt;perform: selector withArguments: argArray inSuperclass: lookupClass</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;NOTE:  This is just like perform:withArguments:, except that</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>the message lookup process begins, not with the receivers&#39;s class,</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>but with the supplied superclass instead.  It will fail if lookupClass</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>cannot be found among the receiver&#39;s superclasses.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>Primitive. Essential. See Object documentation whatIsAPrimitive.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 100&gt;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>(selector isSymbol)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [^ self error: &#39;selector argument must be a Symbol&#39;].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>(selector numArgs = argArray size)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [^ self error: &#39;incorrect number of arguments&#39;].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>(self class == lookupClass or: [self class inheritsFrom: lookupClass])</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [^ self error: &#39;lookupClass is not in my inheritance chain&#39;].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>self primitiveFailed</div></div><div><br></div><div>then redefine perform:withArguments:inSuperclass: to read something like:</div><div><br></div><div><div>
Object&gt;&gt;perform: selector withArguments: argArray inSuperclass: lookupClass</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;NOTE:  This is just like perform:withArguments:, except that</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>the message lookup process begins, not with the receivers&#39;s class,</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>but with the supplied superclass instead.  It will fail if lookupClass</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>cannot be found among the receiver&#39;s superclasses.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Primitive. Essential. See Object documentation whatIsAPrimitive.&quot;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 100&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>(argArray isCollection and: [argArray isSequenceable and: [argArray class ~~ Array]]) ifTrue:<br>
</div><span class="Apple-tab-span" style="white-space:pre">                </span>[^self perform: selector withArguments: argArray asArray inSuperclass: lookupClass].<div><span class="Apple-tab-span" style="white-space:pre">        </span>selector isSymbol</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [^ self error: &#39;selector argument must be a Symbol&#39;].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>selector numArgs = argArray size</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [^ self error: &#39;incorrect number of arguments&#39;].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>(self class == lookupClass or: [self class inheritsFrom: lookupClass])</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [^ self error: &#39;lookupClass is not in my inheritance chain&#39;].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self primitiveFailed</div>
</div><div><br></div><div>c.f. e.g. the asInteger send in</div><div><br></div><div>Object&gt;&gt;at: index </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Primitive. Assumes receiver is indexable. Answer the value of an </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>indexable element in the receiver. Fail if the argument index is not an </div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Integer or is out of bounds. Essential. See Object documentation </div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>whatIsAPrimitive.&quot;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 60&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>index isInteger ifTrue:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>[self class isVariable</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>ifTrue: [self errorSubscriptBounds: index]</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>ifFalse: [self errorNotIndexable]].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>index isNumber</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifTrue: [^self at: index asInteger]</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [self errorNonIntegerIndex]</div>
<div><br></div><div>which allows one to write #(seriously ?) at: 1.0</div><div></div></div><div><br></div><div>HTH,</div><div>Eliot</div>
</div></div>