While everyone is saying what they want in Python :)

Jay O'Connor joconnor at cybermesa.com
Tue Feb 6 23:30:54 EST 2001


On Wed, 7 Feb 2001 02:31:50 +0100, "gzeljko" <gzeljko at sezampro.yu>
wrote:

>
>I agree,
>but this construct can't go in Python
>(what about assigment in this context ?)
>
>Zeljko

Well, I'm not sure about Pascal's 'with' clause (actually, I'm not too
interested in Pascal's 'with' clause.  I was thinking of Smalltalk's
cascading, which is a different concept)

In Smalltalk. the value of a cascaded set of message sends is whatever
the return was of the last messages (intermediate returns get
discarded)

thus in

win := ApplicationWindow new
	name: 'My Window';
	location: (100 @ 100) 

win will be equal to th ereturn value of #location:  Since #location:
is mostly likely an accessor with no explicit return, the default
return of 'self' will be return and win will equal whatever the
receiving object is (in this case, the newly created ApplicationWindow
object)

This gives rise to the rather strange use of #yourself, being a simple
method that returns self.  This is most often used for creating a new
collection with a cascaded approach to populating the collection.

collection := OrderedCollection new
	add: "Terry Gillian";
	add: "John Cleeese";
	add: "Kevin Kilne";
	yourself.

In Smalltalk, the collection method #add: returns the newly added
object.  So in the above case would make collection equal to the
String "Kevin Kline" and not to the newly created collection.
Therefore, #yourself is used as the last cascaded message which simply
returns 'self' and makes sure that collection is indeed set to the
newly created collection 


Take care,


Jay O'Connor
joconnor at cybermesa.com
http://www.cybermesa.com/~joconnor

Python Language Discussion Forum - http://pub1.ezboard.com/fobjectorienteddevelopmentpython

"God himself plays on the bass strings first, when he tunes the soul"



More information about the Python-list mailing list