(1 to: self) inject: 1 into: #*
Jarvis, Robert P. (Contingent)
Jarvisb at timken.com
Wed Jan 19 20:59:21 UTC 2000
Ahem...when I said "Collection protocol" in the second paragraph below I
meant, of course, "BlockContext protocol".
<blush>
[self writeUponBlackboard: 'I will proofread all messages *carefully* before
sending them' ] timesRepeat: 1000.
Bob Jarvis
Compuware @ Timken
> -----Original Message-----
> From: Jarvis, Robert P. (Contingent)
> Sent: Wednesday, January 19, 2000 3:34 PM
> To: 'squeak at cs.uiuc.edu'
> Subject: RE: (1 to: self) inject: 1 into: #*
>
> There are a few issues here:
>
> First, IMO this change just raises the obfuscation quotient. I think it
> would make learning to use these messages harder for beginners as they'd
> have to learn two forms of the message, one using a block as the second
> argument and another using a symbol. Even experienced Smalltalker's might
> have to stop and puzzle this out for a minute before they recognized what
> was going on.
>
> Second, IIRC we went through an exercise a while back to get rid of
> message
> implementations in various classes which, while they were useful, served
> mostly as crutches and/or bandages for problems elsewhere in the image.
> (Someone else will have to chime in with specifics here, as I was only an
> observer of this process). Slapping bits of Collection protocol
> (specifically #value:value:) into Symbol seems to me to be a step
> backwards
> in this regard.
>
> Third, this can produce slow-running code. For example, if
> Integer>>factorial was implemented as you suggest it would run roughly
> twice
> as slowly as it does today. Using your implementation below
>
> Time millisecondsToRun: [ 500 factorial ]
>
> answers 5137. The standard #factorial method takes 2634 milliseconds to
> evaluate "500 factorial".
>
> To use the car salesman's adage, "Oh, sure, you can do that - but you
> wouldn't be happy with it...". :-)
>
> Bob Jarvis
> Compuware @ Timken
>
> > -----Original Message-----
> > From: Mats Nygren [SMTP:nygren at sics.se]
> > Sent: Wednesday, January 19, 2000 2:05 PM
> > To: Squeak
> > Subject: (1 to: self) inject: 1 into: #*
> >
> > Hello,
> >
> > I find the following elegant:
> >
> > aCollection inject: 1 into: #*
> >
> > (and similarly for all binary messages and single-keyword messages)
> >
> > more so than the normal:
> >
> > aCollection inject: 1 into: [ :a :b | a * b]
> >
> > For example like this:
> >
> > factorial
> > (1 to: self) inject: 1 into: #*
> >
> > The price for this seems to be simply:
> >
> > !Symbol methodsFor: 'converting' stamp: 'mn 1/19/2000 19:38'!
> > value: i value: ii
> > ^i perform: self with: ii! !
> >
> > And similarly for unary messages
> >
> > aCollection collect: #negated
> >
> > What do you think?
> >
> > /Mats Nygren
More information about the Squeak-dev
mailing list
|