Messages: Composition and Precedence

Damien Cassou, Stéphane Ducasse and Luc Fabresse http://stephane.ducasse.free.fr

Composition: from Left to Right!

What happens when we have two messages of the same kind?

1000 factorial class name  
> 'LargePositiveInteger'

is equivalent to

(((1000 factorial) class) name) 

Complete Message Precedence

Precedence Example

2 + 3 squared
> 2 + 9
> 11

Precedence Example

2 raisedTo: 3 + 2
> 2 raisedTo: 5
> 32

Precedence Example

Color gray - Color white = Color black
> aGray - aWhite = aBlack
> aBlack = aBlack
> true

Precedence Example

1 class maxVal + 1 
> 1073741824
1 class
> SmallInteger

1 class maxVal
> 1073741823
	
1 class maxVal + 1
> 1073741824
	
(1 class maxVal + 1) class
> LargePositiveInteger

Parentheses take Precedence!

0@0 extent: 100@100 bottomRight
> Message not understood
> 100 does not understand bottomRight

Should use ()

(0@0 extent: 100@100) bottomRight
> (aPoint extent: anotherPoint) bottomRight
> aRectangle bottomRight
> 100@100

The Price for Simplicity

Only messages:

No Mathematical Precedence

3 + 2 * 10
> 5 * 10
> 50
3 + (2 * 10)
> 3 + 20
> 23

No Mathematical Precedence

1/3 + 2/3
> 7/3 /3
> 7/9
(1/3) + (2/3)
> 1

Summary

/