Babysteps in Scala

Published 10 March 08 05:11 AM | andersnoras 

There are always some Java developers who attend whenever I give my .NET DSL talk. This is super cool, and at it makes for some new challenges. The most common one is “How can we do these things with Java”. Since the JavaZone guys have introduced an emerging languages track and extended their call for papers deadline to next month, I figured “porting” the talk to the Java platform would be cool. The downside* is that, until somebody writes “Boo4J”, I have to learn some more “Java” languages to explore the possibilities. I’ve spent a couple of evenings with Scala, and I’m really pleased with what I’ve got so far…

Scala dsl

Being used to mainly using imperative languages, I had to learn a couple of new tricks to get this thing running. The first was how one can pass a first-class function as a by-name parameter. This is used for the predicates. The other was how to use currying to make the when function look like a keyword. The cool thing was that this was super duper simple. All in all, less than 20 (!) lines of code was required. Looks like I’m catching the Scala bug too…

*Well, learning new languages isn’t really a downside…

Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Johannes Brodwall said on March 10, 2008 2:19 PM:

And where is DSL2.scala? :-)

# andersnoras said on March 10, 2008 2:26 PM:

@Johannes:

It's in the ScalaProjects folder! Look at the top of the shell :-P

I'm not going to humiliate myself by releasing the first few lines of Scala code I've ever written. It can't be all that - after all punctuation is kind off optional in Scala, but I couldn't get this thing to compile without the dots in.between.the.words. Can someone tell me why?

# Ayende Rahien said on March 10, 2008 11:13 PM:

Andres,

You are aware that Boo runs on Java, right?

# andersnoras said on March 10, 2008 11:48 PM:

@Ayende:

No I wasn't. That's a game changer! Maybe I should have taken the time to Google for it.

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below