(no subject)

Alan Lovejoy squeak-dev.sourcery at forum-mail.net
Sat Apr 8 06:49:10 UTC 2006


If #do: is to be understood by all objects, then its default behavior should
be to do nothing.  The reason is to avoid semantic inconsistency, since "#()
do: [:x | Transcript cr; show: x printString]" does not result in anything
being displayed on the Transcript.  To put it another way: the semantics of
#do: are that it enumeratates over the contents/elements of the receiver,
specifically excluding the receiver itself.

Whether it is wise for all objects to understand #do: is an entirely
different issue--one that I will leave as an exercise for others to debate,
should they be so inclined.

--Alan

-----Original Message-----
From: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] On Behalf Of Andrew
P. Black
Sent: Friday, April 07, 2006 1:04 PM
To: The general-purpose Squeak developers list
Subject: (no subject)

Does anyone else feel that

	x ifNotNilDo: [: each | Transcript show: each; space].
(1)

and

	x ifNotNil: [ x do: [: each | Transcript show: each; space]].
(2)

ought to do the same thing?

Or perhaps nil should respond to do: (and do nothing?)

The rationale is to be able to use instance variables initialized to nil as
empty collections, without having to  repeatedly test if they are nil before
telling them to do: something, as in phrase (2) above.  One might be
forgiven for thinking that ifNotNilDo: would have the same effect as do: on
a non-nil object.

I realize that it is probably infeasible to make a change like this, but I
couldn't resist thinking about it.

	Andrew






More information about the Squeak-dev mailing list