. .

st4u

ST 4U 387: Cascades and yourself

May 17, 2013 10:01:47.066

Today's Smalltalk 4 You looks at cascades and #yourself. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Cascades.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:


Using Smalltalk, you'll often run across the cascade syntax:


ct := CTest new.
ct options
	add: 1;
	add: 2;
	add: 3;
	add: 4;
	yourself

Here we have a small class with an instance variable, and the variable holds a collection. The use of #add: is followed by a cadcade (the semi-colon). What that does is ensure that the next message (#add: in this case) is sent back to the original receiver (the collection) rather than to the return object (#add: answers the object sent).

So in the example above, without the #yourself at the end, the last message send would answer 4 rather than the collection.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Tags: ,

Enclosures:
[st4u387-iPhone.m4v ( Size: 1756027 )]

posted by James Robertson

 Share Tweet This