Why so few binary method selectors? Because they're bad!

Michael S. Klein mklein at alumni.caltech.edu
Wed Mar 17 19:57:35 UTC 1999


> >down, let me ask the group a question. If we could have long binary
> >method selectors, what would be the first one you would define, and what
> >would it do? Best regards. -- Ward

I've an idea that I've mildly wished for over the years.
First, you have to realize that binary selectors are just syntactic sugar
for keyword messages with one parameter.

Lets you are an accounting firm and you want to know total income of your
clients' handicapped employees. 

((AllClients collect: [:client | client employees])
	select: [:employee | employee isHandicapped])
		inject: 0 into: [ :total :employee | total + employee income]

The trouble is the parenthesis make it a bit annoying.  I'd rather type 
it in using a more "algebraic" fashion.  Something like

AllClients
	{collect} [:client | client employees]
	{select} [:employee | employee isHandicapped]
	inject: 0 into: [ :total :employee | total + employee income]

With a few simple non-domain-specific methods (*) it turns to:

AllClients
	{collect} #employees
	{select} #isHandicapped
	{total} #income

which might as well be one line.

AllClients {collect} #employees {select} #isHandicapped {total} #income

First problem is I haven't found a good syntax it.  I'm not advocating
the '{}' which have allready been coopted by Squeak and Gemstone.

Second problem is I don't want cancer of the semi-colon

-- Mike Klein

mklein at alumni.caltech.edu

(*)

'From Squeak 2.2 of Sept 23, 1998 on 17 March 1999 at 11:51:26 am'!

!Collection methodsFor: 'enumerating' stamp: 'msk 3/17/1999 11:50'!
total: aspectSelector
	^self inject: 0 into: [ :total :each | total + (each perform: 
aspectSelector)]

	" #(1 4 9 16 ) total: #sqrt "! !


!Symbol methodsFor: 'evaluating' stamp: 'msk 3/17/1999 11:47'!
value: parameter
	^parameter perform: self! !





More information about the Squeak-dev mailing list