scala

Syntactic sugar for compile-time object creation in Scala

Lets say I have trait fooTrait[T] { def fooFn(x: T, y: T) : T } I want to enable users to quickly declare new instances of fooTrait with their own defined bodies for fooFn. Ideally, I'd want something like val myFoo : fooTrait[T] = newFoo((x:T, y:T) => x+y) to work. However, I can't just do def newFoo[T](f: (x:T, y:T) => T) =...

How does ScalaTest syntax work?

I've done some programming in Scala, and I know that, e.g., xs map f is the same thing as xs.map(f) but I have no idea how to generalize this syntax to something like ScalaTest's syntax, e.g., it should "throw NoSuchElementException if an empty stack is popped" in { val emptyStack = new Stack[String] evaluating { emptyStack.po...

Easiest way to do idle processing in a Scala Actor?

I have a scala actor that does some work whenever a client requests it. When, and only when no client is active, I would like the Actor to do some background processing. What is the easiest way to do this? I can think of two approaches: Spawn a new thread that times out and wakes up the actor periodically. A straight forward approach,...

Lift and Eclipse RCP Integration

I work on a fairly simple but large two-tier application that consists approximately 40 Eclipse RCP plugins. We have a new use case that is taking us to the web for a very small portion of this functionality. I'd like to prototype this using Lift. Clearly, I'm facing a few challenges. Lift + OSGi. Can Lift get at OSGi bundles? Can...

Int vs Integer: type mismatch, found: Int, required: String

I type these to the scala interpreter: val a : Integer = 1; val b : Integer = a + 1; And I get the message: <console>:5: error: type mismatch; found : Int(1) required: String val b : Integer = a +1 ^ Why? How can I solve this? This time I need Integers due to Java interoperability reasons. ...

Scala and Swing GUI applications

From reading parts of the Programming in Scala book, I realize that Scala can work with the Java Swing components to create GUI applications. My question is if there are any projects or released applications (that are more than just simple examples) that use Scala and Swing? ...

Scala build tool and test framework that play nice together?

Here are my goals: 1. Run my tests in Eclipse and see the pretty green or red bar. 2. Run my tests on the command line with a build tool. I'm leaning towards specs and sbt, but I can't get them to work. I have no desire to pick up Maven. My question is which one of the follow sets works best? sbt and scalatest sbt and specs ant and sc...

How to start external application from Scala

How to start external application from Scala? ...

Source.getLine - the line index, first line is 1

Why index starts from 1 not from 0? http://www.scala-lang.org/docu/files/api/scala/io/Source.html ...

How do I mix JVM based languages in a single Netbeans project?

For example, is it possible to have Scala, Java, and Clojure source all compile/build together properly inside the same project? Or, do I have to do them as separate project libraries then used by whatever I pick as the "master" project? If neither of those, how's everyone else doing it? ...

Scala 2D Animation library

Can anyone recommend a good 2D animation package for Scala? I prefer something which already have some basic events handling, more like JavaFX than like processing.org. ...

Are there code examples comparing Scala and JavaFX Script?

I am studying JavaFX Script and trying to compare it to Scala, which is another very interesting new language for the Java platform. In the official Scala site I found this example, which is a Quick Sort implementation. I then wrote the following equivalent JavaFX Script program (using NetBeans IDE 6.7.1): package examples; function s...

How to access parent element in Scala XML

The scala.xml package represents XML with nodes of a labelled tree. But is this tree unidirectional in Scala 2.7, as there seems to be no way to access the Elem parent of a given Elem? The same seems to apply for parent Document. For example, in XOM you have getParent and getDocument accessors to navigate towards the root of the tree. Ca...

Why is method overloading not defined for different return types?

In Scala, you can overload a method by having methods that share a common name, but which either have different arities or different parameter types. I was wondering why this wasn't also extended to the return type of a method? Consider the following code: class C { def m: Int = 42 def m: String = "forty two" } val c = new C val...

Call hierarchy and/or data flow tool for Scala.

Hi. Is there an IDE/Tool/script/something that can show call hierarchy and/or data flow in Scala+Java programs (preferably from source code). Or (as a backup plan) is there a tool that can show it using Java bytecode? (And preferably give the option to go to source code, if provided by user). All that, preferably integrated into an IDE a...

Using comparison operators in Scala's pattern matching system.

Is it possible to match on a comparison using the pattern matching system in Scala? For example: a match { case 10 => println("ten") case _ > 10 => println("greater than ten") case _ => println("less than ten") } The second case statement is illegal, but I would like to be able to specify "when a is greater than". ...

Scala: how to inherit a "static slot"?

Well, I'm learning Scala so this question may be too basic for most people. In Java I can have a static slot (function or variable) in a class, and then I will have that slot in inherited classes too. In Scala I don't have static slots, but I have companion objects. But I'm finding out that those objects are not part of the inherited c...

Is there a "SELF" type in scala that represents the current type?

I'm learning Scala and there is a thing that I can't find out about the language: Some time ago I was very comfortable programming in Lisaac, and in Lisaac I could write a class PERSON with a slot list:ARRAY[SELF], which was equivalent to have list:ARRAY[PERSON], since SELF is the type of the object where that slot is. But by using SEL...

Scala: set a field value reflectively from field name

I'm learning scala and can't find out how to do this: I'm doing a mapper between scala objects and google appengine entities, so if i have a class like this: class Student { var id:Long var name:String } I need to create an instance of that class, in java i would get the Field by it's name and then do field.set(object, value)...

Initializing Generic Variables in Scala

How do I declare a generic variable in Scala without initializing it (or initializing to any value)? def foo[T] { var t: T = ???? // tried _, null t } ...