Hi Jerome,<div>Igor also replied with comments regarding the proper use of matrices, so I know now that I must have not been clear in my original mail.   Apologies for that.</div><div>I was not interested in discussing the Matrix protocol, but weather or not did people consider it useful to add a method that provides the same functionality as #collect: but without the argument, basically as a method called #timesCollect: of the Integer class, much in the same fashion as #timesRepeat:</div>
<div>With this method one could write code that produces the same result as:</div><div><br></div><div>(1 to: n) collect: [ :i | random next: m ]</div><div><br></div><div>as</div><div><br></div><div>n timesCollect: [ random next: m ]</div>
<div><br></div><div>which does not force the user to visibly create the Interval nor to use a one argument block when the argument is not needed.</div><div><br></div><div>My intention, hence, was only to ask if people would consider it a nice to have method on the Integer class, as a sibling of #timesRepeat:</div>
<div><br></div><div>Cheers</div><div><br></div><div><br><br><div class="gmail_quote">On Thu, May 21, 2009 at 1:11 AM, Jerome Peace <span dir="ltr">&lt;<a href="mailto:peace_the_dreamer@yahoo.com">peace_the_dreamer@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Hi Ramiro,<br>
<br>
<br>
&gt;Ramiro Diaz Trepat ramiro at <a href="http://diaztrepat.name" target="_blank">diaztrepat.name</a><br>
&gt;Wed May 20 08:01:11 UTC 2009 asks:<br>
&gt;<br>
&gt;I have a simple question regarding the use of a proper idiom.I had to create<br>
&gt;a matrix (n X m) of random values and I used a line similar to this one:<br>
&gt;<br>
&gt;NMatrix withRows: ((1 to: n) collect: [ :i | random next: m ]).<br>
&gt;<br>
&gt;Since Smalltalk is so neat for its collection handling, I obviously did not<br>
&gt;like to write that line.<br>
&gt;I thought that I did not want to explicitly create the interval, nor use a<br>
&gt;block that requires an<br>
&gt;argument that I also don&#39;t use.<br>
&gt;The question, finally, is if there an elegant way of replicating the<br>
&gt;behaviour of #collect: but<br>
&gt;without the argument?<br>
&gt;In my case, I thought it would be great for Integer to have something like<br>
&gt;#timesCollect:<br>
&gt;that would allow me to rewrite the line above as:<br>
&gt;<br>
&gt;NMatrix withRows: (n timesCollect: [ random next: m ])<br>
&gt;<br>
&gt;Does anyone else think that this would be an useful method to have?<br>
<br>
In a workspace evaluate:<br>
<br>
picker := Random new .<br>
<br>
(Matrix rows: 2 columns: 3 ) collect: [ :each | picker next ] .<br>
<br>
result:<br>
<br>
 a Matrix<br>
(0.2668126189461036 0.319686627164337 0.973142751014392<br>
 0.610216298890401 0.905335450966533 0.97292439452043)<br>
<br>
You may wish to study the Matrix class and see what else it can do.<br>
The class is a recent contribution by someone who had a need for it.<br>
<br>
Hth,<br>
<br>
Yours in curiosity and service, --Jerome Peace<br>
<br>
<br>
<br>
<br>
</blockquote></div><br></div>