(1 to: self) inject: 1 into: #*

Mats Nygren nygren at sics.se
Wed Jan 19 19:04:51 UTC 2000


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