Monday, November 15, 2010

Scala in Stalled

A play on the Scala in Action title of the Manning book. :)

I have started using Homebrew and it is pretty close to perfect. The Scala install is the first issue I've had.
[greg:local] brew install scala
==> Downloading http://www.scala-lang.org/downloads/distrib/files/scala-2.8.1.final.tgz
######################################################################## 100.0%
/usr/local/Cellar/scala/2.8.1: 113 files, 22M, built in 2 seconds
[greg:local] scala
-bash: /opt/scala-2.7.5.final/bin/scala: No such file or directory
[greg:local] sudo scala
Password:
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 1 + 2
res0: Int = 3

scala>
Now we know what makes it work and how to correct the issue:
[greg:local] chmod 755 /usr/local/Cellar/scala/2.8.1/bin/*
[greg:local] scala
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.

scala> 1 + 9
res0: Int = 10

scala> val myList = new java.util.ArrayList[String]()
myList: java.util.ArrayList[String] = []

scala> myList.add("Hello") 
res1: Boolean = true

scala> myList.add("World")
res2: Boolean = true

scala> myList
res3: java.util.ArrayList[String] = [Hello, World]

scala> myList.<TAB>

add              addAll           asInstanceOf     clear            clone            contains
containsAll      ensureCapacity   get              indexOf          isEmpty          isInstanceOf
iterator         lastIndexOf      listIterator     remove           removeAll        retainAll
set              size             subList          toArray          toString         trimToSize

scala> 1.<TAB>     

%              &              *              +              -              /              >
>=             >>             >>>            ^              asInstanceOf   isInstanceOf   toByte
toChar         toDouble       toFloat        toInt          toLong         toShort        toString
unary_+        unary_-        unary_~        |

scala> 1.
Enter the name of a variable and the dot operator and press TAB to list the object's methods.