[squeak-dev] One liner challenge

Igor Stasenko siguctua at gmail.com
Fri Mar 12 05:11:14 UTC 2010


On 12 March 2010 06:56, Josh Gargus <josh at schwa.ca> wrote:
> #upTo: is inconvenient for this because the result doesn't include the matched character.  If we had #upToWith: we could write:
>
> | in | in := 'This is a (string) with some (parenthetical fields)' readStream.
> String streamContents: [:out | [in atEnd] whileFalse: [out nextPutAll: (in upToWith: $( ); nextPutAll: (in upToWith: $) ) asUppercase]]
>
a slight variation
| f | f := false.
'This is a (string) with some (parenthetical fields)' collect: [:c | c
= $( ifTrue: [f:=true]. c = $) ifTrue: [f:=false]. f ifTrue: [ c
asUppercase] ifFalse: [c]]

| f | f := #yourself.
'This is a (string) with some (parenthetical fields)' collect: [:c | c
= $( ifTrue: [f:=#asUppercase]. c = $) ifTrue: [f:=#yourself].
c perform: f]


> Cheers,
> Josh
>
>
> On Mar 11, 2010, at 7:34 PM, Randal L. Schwartz wrote:
>
>>>>>>> "Travis" == Travis Griggs <travisgriggs at gmail.com> writes:
>>
>> Travis> Given strings of the form
>>
>> Travis> 'This is a (string) with some (parenthetical fields)'
>>
>> Travis> turn them into
>>
>> Travis> 'This is a (STRING) with some (PARENTHETICAL FIELDS)'
>>
>> Somehow, I think streams and #upTo: are gonna be the key there.
>>
>> --
>> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
>> <merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
>> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
>> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
>>
>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list