Collecting Smalltalk idioms
Dana.Anthony at sas.com
Tue Aug 10 17:22:59 UTC 1999
Re: Jesse's code below, I (and I didnt invent this, but I forget where
I got it from, someone at KSC I am sure) always used:
aCollection inject: '' into: [ :divider :each |
aStream nextPutAll: divider.
each printOn: aStream.
or something of that sort.
Jesse Welton wrote:
> 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.
> 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.
Dana Lynne Goldblatt Anthony
Internet Publications Technology at SAS Institute
World Headquarters Cary, NC, USA
More information about the Squeak-dev