View this PageEdit this PageUploads to this PageVersions of this PageHomeRecent ChangesSearchHelp Guide

cascades

The behavior of cascades takes a bit to get used to. You should use a cascade is when you want to send a sequence of messages to the same object. So for example, if you have:
	| names reversedNames |
	names := OrderedCollection new.
	names add: 'Fred Rogers'.
	names add: 'Bozo The Clown'.
	names add: 'Captain Kangaroo'.
	names add: 'Ray Rayner'.
	reversedNames := names reverse.
	
You are sending the a sequence of messages to the same object; the "names" collections. Using a cascade would make the code less repetitive and easier to understand:
	| reversedNames |
	reversedNames := 
	    OrderedCollection new
	        add: 'Fred Rogers';
	        add: 'Bozo The Clown';
	        add: 'Captain Kangaroo';
	        add: 'Ray Rayner';
	        reverse.
The return value is the result of the last message send in the cascade.

The 2nd thru Nth messages of a cascade are sent to the receiver of the 1st message is the cascading sequence.

So for example this statement:
	3 + 1 raisedTo: 3; raisedTo: 2.
is the same as these statements:
	4 raisedTo: 3.
	4 raisedTo: 2.
	
The integer 4 is the receiver of first message in the cascade.

Link to this Page

  • MP1 Discussion last edited on 4 June 2007 at 11:48:09 am by wakeland-254.flexabit.net