Collecting Smalltalk idioms
Jesse Welton
jwelton at pacific.mps.ohio-state.edu
Tue Aug 10 16:33:26 UTC 1999
Bob Arning wrote:
>
> On Tue, 10 Aug 1999 07:54:47 -0700 Stephen Pope <stp at create.ucsb.edu>
> wrote:
> >
> >Another option is the ugly (but simple)
> >
> > aCollection do:
> > [:each |
> > each printOn: aStream.
> > aStream nextPut: $,].
> > aStream skip: -1
>
> Except for the situation where the collection is empty. I posted a fix
> for just such code yesterday.
Hmm... What about this?
aCollection inject: #NoneYet into:
[:prev :each |
(prev == #NoneYet) ifFalse: [aStream nextPut: $,].
each printOn: aStream.
each].
It's uglier, and less simple, and it doesn't work if #NoneYet makes
its way into aCollection, and I may have newbily screwed it up anyway,
but at least it was fun. And I think it works.
-Jesse
More information about the Squeak-dev
mailing list
|