Friday, July 17, 2009

Stupid Emoticon Tricks

Just for giggles, I decided to see if could get emoticons to compile in Scala. Randomly picking from the Wikipedia page for Eastern-style emoticons, I find I can compile the following code:


package blevins.emoticon

object App extends Application {
import Emoticon._

val emoticons: List[Emoticon] =
List(
( ^ _ ^ ) ,
( ^ o ^ ) ,
d ( ^ _ ^ ) b ,
( T _ T ) ,
( Z . Z )
)

for ( f <- emoticons ) { f.print }
}



It outputs the following:

(^_^)
(^o^)
d(^_^)b
(T_T)
(Z.Z)


The contents of the Emoticon object is left as an exercise for the reader. Note that I was unable to do the (-.-)Zzz emoticon, but maybe that is just because I didn't try hard enough.

If this doesn't convince you to return to Java, nothing will...

1 comment:

Anonymous said...

That's overkill. Scala has plenty of built-in emoticons, such as the vampire pope, for adding to a sequence: +:= or the sad witch, for comparing manifests: <:<

But I see you prefer Eastern-style emoticons, which are more rare in Scala. :/