nosewheelie

Technology, mountain biking, politics & music.

Archive for January, 2008

Scala with Instinct

with one comment

I was lucky enough to spend that last half of last week in a Scala course run by Tony Morris (contact us at Workingmouse if you’re interested in Scala or the course).

The Scala syntax is very malleable and lends itself well to expressing DSLs. With this in mind, here’s a simple Instinct specification written in Scala (it doesn’t work yet, though I think this is an IDE issue, rather than a limitation)

import com.googlecode.instinct.marker.annotate.Specification
import com.googlecode.instinct.integrate.junit4.InstinctRunner
import org.junit.runner.RunWith

@RunWith(classOf[InstinctRunner])
class AnEmptyStack {
    @Specification
    def isEmpty = {}
}

Once we get the next release out, I’d like to spend some time playing around with using Scala to spec Java objects, there should be no reason it can’t also be used to spec out Scala code also (there may be some other things we need to do).

Here’s some RSpec like (valid) Scala:

describe "An empty stack" = {
    it "is empty" = {}
}

Written by Tom Adams

January 14th, 2008 at 11:27 am

Posted in Instinct,Java,Scala,TDD

Installing Scala 2.6.1. on Leopard

with 2 comments

A quick howto on installing Scala 2.6.1 on Mac OS X 10.5 Leopard. I assume a similar set of steps will work on Debian-based Linux distros.

Firstly install MacPorts, secondly install rlwarp & scala.

[/Users/atom] sudo port install rlwrap
...
--->  Attempting to fetch expat-2.0.1.tar.gz from http://downloads.sourceforge.net/expat
...
--->  Attempting to fetch libiconv-1.12.tar.gz from http://ftp.gnu.org/gnu/libiconv
...
--->  Attempting to fetch gettext-0.17.tar.gz from http://ftp.gnu.org/gnu/gettext
...
--->  Attempting to fetch gawk-3.1.5.tar.bz2 from http://ftp.gnu.org/gnu/gawk
...
--->  Attempting to fetch ncurses-5.6.tar.gz from http://ftp.gnu.org/gnu/ncurses
...
--->  Attempting to fetch rlwrap-0.24.tar.gz from http://utopia.knoware.nl/~hlub/uck/rlwrap/
...
--->  Installing rlwrap 0.24_0
--->  Activating rlwrap 0.24_0
--->  Cleaning rlwrap
[/Users/atom] sudo port install scala
--->  Fetching scala
--->  Attempting to fetch scala-2.6.1-final.tar.bz2 from http://www.scala-lang.org/downloads/distrib/files/
--->  Verifying checksum(s) for scala
--->  Extracting scala
--->  Configuring scala
--->  Building scala with target all
--->  Staging scala into destroot
--->  Installing scala 2.6.1_0
--->  Activating scala 2.6.1_0
--->  Cleaning scala

[/Users/atom] rlwrap scala
Welcome to Scala version 2.6.1-final.
Type in expressions to have them evaluated.
Type :help for more information.

scala>

I’ve not tested this in anger yet, but will be doing the patented Tony’s Scala course for the next few days so will have some time to comment on whether it stands up (e.g. most Java & Ruby devs roll their own installations rather than package managed ones).

Update: If you are using the IntelliJ IDEA plugin (more on that later) the home for the Scala SDK is /opt/local/share/scala/share/scala

Written by Tom Adams

January 8th, 2008 at 3:03 pm

Posted in Scala