[squeak-dev] Smalltalk idiom

Ramiro Diaz Trepat ramiro at diaztrepat.name
Wed May 20 08:01:11 UTC 2009


I have a simple question regarding the use of a proper idiom.I had to create
a matrix (n X m) of random values and I used a line similar to this one:

NMatrix withRows: ((1 to: n) collect: [ :i | random next: m ]).

Since Smalltalk is so neat for its collection handling, I obviously did not
like to write that line.
I thought that I did not want to explicitly create the interval, nor use a
block that requires an
argument that I also don't use.
The question, finally, is if there an elegant way of replicating the
behaviour of #collect: but
without the argument?
In my case, I thought it would be great for Integer to have something like
#timesCollect:
that would allow me to rewrite the line above as:

NMatrix withRows: (n timesCollect: [ random next: m ])

Does anyone else think that this would be an useful method to have?

Cheers


r.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090520/10dec9b1/attachment.htm


More information about the Squeak-dev mailing list