scala

Positioning for Scala or Lift jobs

I'm starting to understand Scala and I like it a lot. How can you position yourself to get a paying job as a Scala developer (assuming those become more common)? What parts of the Scala ecosystem have the best job potential (Lift, Actors?). How can you gain credibility with a prospective employer without being able to point to Scala...

How to compile scala sources via maven integration in intellij idea?

I am learning circumflex orm and using maven with idea for the first time. I expected that my sources in src will compile to build directory. But it doesn't happen. And if I specify sourceDirectory and outputDirectory like ${basedir}/src or ${project.basedir}/build I get intellij idea's inspections that such folders doesn't exist (sic!) ...

Compile error in scala, why: val num =123;println(num.getClass())

I'm new to scala. I tried this code: val name = "mike" println(name.getClass()) It's OK and printed java.lang.String But, when I try: val num = 123 println(num.getClass()) There is such a compiler error: type mismatch; found : Int required: ?{val getClass: ?} Note: primitive types are not implicitly converted to AnyRef. You can...

Question about Scala variable Mutability

Hi I understand that val keyword determines the underlying variable is a Immutable type (Cannot be reassigned later time). Now i come across a paragraph in programming in scala (Chapter 3, Next steps in scala - parameterize arrays with types), it states val greetStrings: Array[String] = new Array[String](3) greetStrings(0) = "Hello" gr...

How to inspect an object in script like in scala console?

When I use scala console, it prints an object in a clear style, e.g. scala> val mike = ("mike", 40, "New York") mike: (java.lang.String, Int, java.lang.String) = (mike,40,New York) But if I write in a script file, like: val mike = ("mike", 40, "New York") println(mike) It only prints: (mike,40,New York) How can I do in script fi...

Scala Parser Combinators tricks for recursive bnf?

Im trying to match this syntax: pgm ::= exprs exprs ::= expr [; exprs] expr ::= ID | expr . [0-9]+ My scala packrat parser combinator looks like this: import scala.util.parsing.combinator.PackratParsers import scala.util.parsing.combinator.syntactical._ object Dotter extends StandardTokenParsers with PackratParsers { lexical.del...

Simple question about tuple of scala

I'm new to scala, and what I'm learning is tuple. I can define a tuple as following, and get the items: val tuple = ("Mike", 40, "New York") println("Name: " + tuple._1) println("Age: " + tuple._2) println("City: " + tuple._3) My question is: How to get the length of a tuple? Is tuple mutable? Can I modify its items? Is there any o...

Scala for comprehensions and partial map

The Scala language specification section 6.19 says: A for comprehension for (p <- e) yield e0 is translated to e.map { case p => e0 } So... scala> val l : List[Either[String, Int]] = List(Left("Bad"), Right(1)) l: List[Either[String,Int]] = List(Left(Bad), Right(1)) scala> for (Left(x) <- l) yield x res5: List[String] = List(Bad)...

How should I handle blocking operations when using scala actors?

I started learning the scala actors framework about two days ago. To make the ideas concrete in my mind, I decided to implement a TCP based echo server that could handle multiple simultaneous connections. Here is the code for the echo server (error handling not included): class EchoServer extends Actor { private var connections = 0 ...

Why do Java programmers love Scala and shy away from Clojure?

I've just started to learn Clojure by reading some tutorials and watching every presentation by Rich Hickey, and I'm totally impressed by the language... so different from any C-like language (actually any language I've seen so far), yet so elegant... So I started to wonder... why is everyone so thrilled by Scala but not by Clojure? Is i...

Read a file's lines in Scala 2.7, keeping line terminators.

Hi Guys, The getLines() method of scala.io.Source strips \r and \n from the lines it returns. I instead want to keep those characters in the returned Strings. getLines' comment says: returns lines (NOT including newline character(s)) [...] if you need more refined behavior you can subclass Source#LineIterator I've tried to subcla...

Scala parser combinators for language embedded in html or text (like php)

I have been playing around with Scala parser combinators for some time now, and learned some of the ways to make it behave nicely and do the most of the things I want, using the built in function. But how do you make an embedded language (like php or ruby's erb)? It requires whitespace to not be ignored, outside the embedding of real...

Scala multiple assignment to existing variable

I can do something like def f(): Tuple2[String, Long] = ... val (a, b) = f() What about if the variables are already existing? I'm running the same sets of data over filters and I don't want to chain them (long names and such). This is what I tried, but it complains about expecting ; instead of = on the last line: var a = ...initia...

Scala - menu bar only appears when window contents revalidated

import scala.swing._ import swing.event.{WindowClosing} import java.awt.Dimension object MenuBarTest { def main(args:Array[String]) { val frame = new Frame() { visible=true contents = new Panel() { preferredSize = new Dimension(600,400) } title = "Test" reactions += { case WindowClosi...

"+=" will reassign or not?

See the following code: val names = Set("Mike", "Jack") names += "Jeff" There will be an error: error: reassignment to val I see in some books, it said += is actually a method, and the code can be: val names = Set("Mike", "Jack") names.+=("Jeff") If += is a method, why will it assign the "names"? ...

What is most efficient way to do immutable byte arrays in Scala?

I want to get an array of bytes (Array[Byte]) from somewhere (read from file, from socket, etc) and then provide a efficient way to pull bits out of it (e.g. provide a function to extract a 32-bit integer from offset N in array). I would then like to wrap the byte array (hiding it) providing functions to pull bits out from the array (pro...

Two sets of constructor parameters in a scala class

What does this code do? Why is there two sets of constructor parameters? class A(val x: Int)(val y: Int) I can initialize an object and use both fields: val a = new A(5)(7) println(a.x + ", " + a.y) If I make it a case class, I can match only by the first set of parameters. case class A(x: Int)(y: Int) val a = A(5)(7) a match { ...

Type inference question using Scalaz.ListW.<^>

I was playing around with ListW.<^>, the definition of which is as follows: def <^>[B: Zero](f: NonEmptyList[A] => B): B = value match { case Nil => ∅ case h :: t => f(Scalaz.nel(h, t)) } I cannot figure out how come Option is being chosen as the Zero type for this example scala> case class CC(v : Int) defined class CC scala> va...

What is a DList?

I tried googling for this but all I got were stories about minor celebrities. Given the lack of documentation, what is a DList? ...

Scala abstract method is null in superclass when subclass implements it using val?

I found an error in my scala code, which puzzles me. Below is a simplified version of the problem. In the constructor of an abstract class, I want to check a few asserts about the abstract methods. Thus when an object of a subclass is made, these asserts are checked, to see if all is implemented as it should. It goes wrong when the sub...