[squeak-dev] Smalltalk idiom

Mariano Martinez Peck marianopeck at gmail.com
Thu May 21 12:34:33 UTC 2009


On Thu, May 21, 2009 at 7:40 AM, Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:

> Ah, some s missing!
> If only I could evaluate it from gmail!


I could be easy to create a gtalk bot than can receive smalltalk code and
evaluates hahaha


>
>
> Matrix rows: 2 columns: 5 contents: (Random new next: 10).
>
> 2009/5/21 Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
> > I think it would be more usefull to have some generator behaving like
> Stream.
> > In this particular case, Random is already anamorphic to a Stream:
> >
> > Matrix row: 2 column: 5 contents: (Random new next: 10).
> >
> > Nicolas
> >
> > 2009/5/21 Ramiro Diaz Trepat <ramiro at diaztrepat.name>:
> >> Hi Jerome,
> >> 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.
> >> 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:
> >> With this method one could write code that produces the same result as:
> >> (1 to: n) collect: [ :i | random next: m ]
> >> as
> >> n timesCollect: [ random next: m ]
> >> which does not force the user to visibly create the Interval nor to use
> a
> >> one argument block when the argument is not needed.
> >> 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:
> >> Cheers
> >>
> >>
> >> On Thu, May 21, 2009 at 1:11 AM, Jerome Peace <
> peace_the_dreamer at yahoo.com>
> >> wrote:
> >>>
> >>> Hi Ramiro,
> >>>
> >>>
> >>> >Ramiro Diaz Trepat ramiro at diaztrepat.name
> >>> >Wed May 20 08:01:11 UTC 2009 asks:
> >>> >
> >>> >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?
> >>>
> >>> In a workspace evaluate:
> >>>
> >>> picker := Random new .
> >>>
> >>> (Matrix rows: 2 columns: 3 ) collect: [ :each | picker next ] .
> >>>
> >>> result:
> >>>
> >>>  a Matrix
> >>> (0.2668126189461036 0.319686627164337 0.973142751014392
> >>>  0.610216298890401 0.905335450966533 0.97292439452043)
> >>>
> >>> You may wish to study the Matrix class and see what else it can do.
> >>> The class is a recent contribution by someone who had a need for it.
> >>>
> >>> Hth,
> >>>
> >>> Yours in curiosity and service, --Jerome Peace
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >>
> >>
> >>
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20090521/7b5b9a75/attachment.htm


More information about the Squeak-dev mailing list