Appending a character to a string

Klaus D. Witzel klaus.witzel at cobss.com
Sun Feb 11 20:12:27 UTC 2007


On Sun, 11 Feb 2007 19:26:56 +0100, <dpharris at telus.net> wrote:
> Quoting Alan Kay <alan.kay at squeakland.org>:
>
>> Hi Folks --
>>
>> Damien is asking very reasonable questions, and I don't think that
>> work-around answers are in the spirit of his questions. The Smalltalk
>> ancestors of Smalltalk-80 had better answers to both of these, which
>> were inspired by similar practices in both Lisp and APL.
>>
>> Cheers,
>>
>> Alan
>>
>>
>>
> Alan-
>
> It would have been nice for you to actually tell us what those answers  
> are,
> rather than titillating us ;-).
>
> While I have followed Smalltalk for years, I have only recently started a
> project where I need to use it.  I have found it rather frustrating in  
> that,
> while I can discover the answers by rooting through the classes, it is  
> not
> easy.  I, too, was surprised that I could not do things with  
> collections, but
> rather had to use a subclass.  The adding a character problem cropped up  
> very
> early in my explorations, and all the solutions seemed to be excessively
> wordy.

SequenceableCollection>>#copyWith: newElement
	"Answer a copy of the receiver that is 1 bigger
	 than the receiver and has newElement as the
	 last element."

This is from the (famous) Blue Book and the comment is still the same in  
the Squeak image. Nothing has less words *and* is faster (in Smalltalk,  
that is ;-)

> I expect part of my problem is unfamiliarity with the (vast) set of tools
> available to discover the needed methods.  However, this is part of the  
> large
> learning curve of Smalltalk that people complain about.
>
> Actually, if someone could remind me of how to find a method by my  
> giving an
> example --- 1 ? 1 -> 2 .  I know this exists, but have no idea where to  
> find
> it, not documentation on it.

As Frank already wrote, you might want to use, from the Tools flap,  
"Method Finder".

For the example in this thread, this tool suggests, for

  'ab'. $c. 'abc'

to use

'ab' copyWith: $c => 'abc'

HTH.

/Klaus

> Thanks,
> David
>
>
>
>
>
>
>





More information about the Squeak-dev mailing list