Collecting Smalltalk idioms

Randal L. Schwartz merlyn at
Tue Aug 10 18:26:39 UTC 1999

>>>>> "Marcel" == Marcel Weiher <marcel at> writes:

Marcel> Turning it into the standard #do:separatedBy: would then look  
Marcel> something like this:

Marcel> do:operation separatedBy:separator
Marcel> 	self inject: [] into: [ :divider :each |
Marcel> 		  divider value.
Marcel> 		  operation value:each.
Marcel> 		  separator
Marcel> 	].

This seems "unclean" to me.  We're sending a needless "value" to an
empty block.

I'd rather see something like:

do: operation separatedBy: separator

	self inject: true into: [ :firstTime :each |
		firstTime ifFalse: [separator value].
		operation value: each.

If you'll indulge me.  It'll probably even bytecompile tighter. :)

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at> <URL:>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See for onsite and open-enrollment Perl training!

More information about the Squeak-dev mailing list