scala

Scala Eclipse Autocomplete Broken?

Hi All, I'm trying to get autocomplete working in eclipse for scala development. I'm trying to reference a java class from a Scala class, and the autocomplete feature never finds it. for example take this scala class: object Main { def main(args: Array[String]) { val btn = new JButton } } When I hit ctrl+space at the end of typ...

How can I create a jar from some Scala source code?

How can I create a jar from some Scala source code? I want to use some of that code in a Clojure project of mine. Is there a simpler way than doing batch files as in this SO question? Thanks, Alex ...

Does Scala have an API method that converts a Seq[Option[T]] to Seq[T]?

Is there a Scala API method to convert a Seq[Option[T]] -> Seq[T]? You can do this manually via: seq.filter(_.isDefined).map(_.get) Wondering if there is a method that does the above in the general API. ...

Scala: Filtering based on type

I'm learning Scala as it fits my needs well but I am finding it hard to structure code elegantly. I'm in a situation where I have a List x and want to create two Lists: one containing all the elements of SomeClass and one containing all the elements that aren't of SomeClass. val a = x collect {case y:SomeClass => y} val b = x filterNot ...

Scala Annotation List?

I wanted to ask if there is a list of annotations for Scala 2.8.0? I stumbled upon @inline and @specialized but it would be nice if there is a complete list which also explains what they do exactly. If such a list doesn't exist: Are there some annotations one should be familiar with? ...

Custom control structures in Scala?

There are a number of times I've run into a simple pattern when programming in Java or C++ for which a custom control structure could reduce the boilerplate within my code. It goes something like: if( Predicate ){ Action return Value } that is, a "return if"-type statement. I've tried making functions with signature lik...

Mocking scala object

I am using mockito and trying to mock a scala object. object Sample { } //test class SomeTest extends Specification with ScalaTest with Mockito { "mocking should succeed" in { val mockedSample = mock[Sample] } } Give me 2 compilation errors. error: Not found type Sample error: could not find implicit value for parameter...

; expected but <place your favourite keyword here> found

Hello everyone, I'm trying to write a class for a scala project and I get this error in multiple places with keywords such as class, def, while. It happens in places like this: var continue = true while (continue) { [..] } And I'm sure the error is not there since when I isolate that code in another class it doesn't give me any e...

Using scala to call java.util.Hashtable#put

I've an unexpected trouble calling put on an old-school hashtable. What's going on here? Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_21). Type in expressions to have them evaluated. Type :help for more information. scala> import com.ibm.mq._ import com.ibm.mq._ scala> MQEnvironment.pro...

Lift Framework BindHelpers.attr Question (or better practice?)

My problem is extracting xhtml attributes to generate absolute links, since they need to be different on testing and production environment. I would like to use a "global snippet" that binds all "src" and "href" attributes to "localhost:8080" or "www.mydomain.com" depending on a conf value. This is how the template looks like: <lift:Gl...

In a multidimensional sequence created with tabulate, is the innermost seq the 1. dimension?

As the title says, when creating a multidimensional sequence in scala with tabulate, is the innermost or outermost sequence the 1. dimension? For example, in a 2-dimensional Vector v, will v(2) give the second element of the 1. or of the 2. dimension? ...

scala list match

List(1,2) match { case List(1,_) => println("1 in postion 1") case _ => println("default") } compiles / works fine. So do List(1) match ... List(3,4,5) match ... but not List() match ... which results in the following error found : Int(1) required : Nothing case List(1,_) => println("1 in postion 1") Why does...

Why is implicit conversion from Long to RichLong not applied where a supertype of RichLong is expected?

Scala 2.8 spec says in section 7.3 (highlighting is mine): Implicit parameters and methods can also define implicit conversions called views. A view from type S to type T is defined by an implicit value which has function type S=>T or (=>S)=>T or by a method convertible to a value of that type. Views are applied in two situati...

How does Scala's (2.8) Manifest work?

I have some Scala code that makes fairly heavy use of generics, and I have gleaned from the docs that using a manifest in the parametrization constraints can help me work around the type erasure issues (e.g. I want to instantiate a new object of the generic type). Only, I'd like to understand more about how this works. It almost feels li...

What are the benefits of using Scala in .Net?

Scala is a peculiar programming language in that it targets both JVM and the CLR. But what are the benefits? Is it worth considering it as a viable alternative to the F# language? ...

try block scope

I'm unhappy with the rule about variable scope in a try block not being shared with associated catch and finally blocks. Specifically it leads to code like the following: var v: VType = null try { v = new VType() } catch { case e => // handle VType constructor failure (can reference v) } finally { // can reference v. } As oppos...

Way to reduce the redundancy in following boolean function definitions?

Hi, I am just looking for better Scala ways of doing things, so asking newbie questions. For example: I wanted to be able to do things like the following: Given a,b,c which are "boolean": if (((a nand b) nand c) != (a nand (b nand c))) printf("NAND is not associative") Where I would cycle through possible a,b,c boolean values. I ...

Redefining ENTER key in Emacs

I don't know elisp, but I'm trying to do something like the following: (add-hook 'scala-mode-hook (lambda () (define-key scala-mode-map (kbd "RET") (lambda () (scala-newline) (scala-indent-line))))) Goal is to call the two functions each time ...

Correct usage of mutable/immutable lists

At the moment, Im trying to understand Functional Programming in Scala and I came across a problem I cannot figure out myself. Imagine the following situation: You have two classes: Controller and Bot. A Bot is an independent Actor which is initiated by a Controller, does some expensive operation and returns the result to the Controll...

What are the alternatives to subtype polymorphism in scala?

I'm interested to know the complete set of alternatives to subtype polymorphism in scala. ...