[squeak-dev] One liner challenge

Travis Griggs travisgriggs at gmail.com
Fri Mar 12 06:41:27 UTC 2010


Here's 3 solutions from me:

Similar to others:

coercion := #yourself.
string collect:
		[:c |
		coercion := c = $(
					ifTrue: [#asUppercase]
					ifFalse: [c = $) ifTrue: [#yourself] ifFalse: [coercion]].
		c perform: coercion]

Requires VW specific methods piecesCutWhere: and fold:

((string piecesCutWhere: [:a :b | b = $( or: [a = $)]])
	collect: [:phrase | phrase first = $( ifTrue: [phrase asUppercase]  
ifFalse: [phrase]])
		fold: [:a :b | a , b]

I know Eliot and others know how to write both of these methods,  
nudge, nudge :)

Requires VW difference engine that shows up in tomorrows build (I  
regret that this ends making my original post look like an opportunity  
to tout this. I honestly didn't even think about the differences  
engine, it was only later this evening while I was thinking about ways  
to solve it, that this donned on me):

(string differences: (string reject: [:c | '()' includes: c]))
	fold: [:a :b | a , (a last = $( ifTrue: [b collect: #asUppercase]  
ifFalse: [b])]

This last one is definitely terse and elegant, but much more obscure  
how it actually pulls it off.

--
Travis Griggs
Objologist
I multiply all time estimates by pi, to account for running around in  
circles.






More information about the Squeak-dev mailing list