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"><<a href="mailto:peace_the_dreamer@yahoo.com">peace_the_dreamer@yahoo.com</a>></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>
>Ramiro Diaz Trepat ramiro at <a href="http://diaztrepat.name" target="_blank">diaztrepat.name</a><br>
>Wed May 20 08:01:11 UTC 2009 asks:<br>
><br>
>I have a simple question regarding the use of a proper idiom.I had to create<br>
>a matrix (n X m) of random values and I used a line similar to this one:<br>
><br>
>NMatrix withRows: ((1 to: n) collect: [ :i | random next: m ]).<br>
><br>
>Since Smalltalk is so neat for its collection handling, I obviously did not<br>
>like to write that line.<br>
>I thought that I did not want to explicitly create the interval, nor use a<br>
>block that requires an<br>
>argument that I also don't use.<br>
>The question, finally, is if there an elegant way of replicating the<br>
>behaviour of #collect: but<br>
>without the argument?<br>
>In my case, I thought it would be great for Integer to have something like<br>
>#timesCollect:<br>
>that would allow me to rewrite the line above as:<br>
><br>
>NMatrix withRows: (n timesCollect: [ random next: m ])<br>
><br>
>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>