scala-2.8

Scala: What is the right way to build HashMap variant without linked lists ?

How mouch Scala standard library can be reused to create variant of HashMap that does not handle collisions at all? In HashMap implementation in Scala I can see that traits HashEntry, DefaultEntry and LinkedEntry are related, but I'm not sure whether I have any control over them. ...

How to get Ponter/Reference semantics in Scala.

In C++ I would just take a pointer (or reference) to arr[idx]. In Scala I find myself creating this class to emulate a pointer semantic. class SetTo (val arr : Array[Double], val idx : Int) { def apply (d : Double) { arr(idx) = d } } Isn't there a simpler way? Doesn't Array class have a method to return some kind of reference to a p...

Iterators for mutable collections in Scala?

I just found out that there are such iterators in Java. Does Scala have iterators with 'set' and 'remove' methods for iterating (and modifying) mutable collections like array? If there is no such iterator then is there a good reason for that? ...

Scala simple dummy project.

Currently my whole work cycle is: edit foo.scala fsc foo.scala && scala -cp . FooMain But my project is getting bigger and I would like to split files, make unit tests, etc. But I'm too lazy for reading sbt documentation and doing whatever needs to be done to get a sbt's "Makefile". Similarly for unit tests (there are so many framewo...

Assign method in Scala.

When this code is executed: var a = 24 var b = Array (1, 2, 3) a = 42 b = Array (3, 4, 5) b (1) = 42 I see three (five?) assignments here. What is the name of the method call that is called in such circumstances? Is it operator overloading? Update: Can I create a class and overload assignment? ( x = y not x(1) = y ) ...

CPS/Continuations StackOverflowError on (tail-)recursive functions

Hello, is there any way to have a tail-recursive function inside CPS not throwing a StackOverflow? import scala.util.continuations._ object CPSStackOverflow { def main(args: Array[String]) = { reset { def recurse(i: Int): Unit @suspendable = { println(i) shift { k: (Unit => Unit) => k( () ) // just ...

Best Functional Approach

I have some mutable scala code that I am trying to rewrite in a more functional style. It is a fairly intricate piece of code, so I am trying to refactor it in pieces. My first thought was this: def iterate(count:Int,d:MyComplexType) = { //Generate next value n //Process n causing some side effects return iterate(count - 1, n) }...

What are nested/unnested packages in Scala 2.8?

In Scala 2.7, I could write: package com.acme.bar class Bar . package com.acme.foo class Foo { new bar.Bar } This doesn't compile in Scala 2.8 -- however this does: package com.acme package bar class Bar . package com.acme package foo class Foo { new bar.Bar } What was the motivation for this? What is the precise ...

How can Scala actors return a value in response to a message?

There are plenty of examples of actors replying with another message back to the sender, but whilst browsing the API docs I noticed the !! and !? operators which are part of the CanReply trait (which seems to be new to 2.8: http://www.scala-lang.org/archives/rc-api/scala/actors/CanReply.html). I was therefore wondering whether it was jus...

Scala 2.8: use Java annotation with an array parameter

I'm trying to implement an JavaEE Session Bean with Scala 2.8. Because it's a Remote Session Bean, i have to annotate it with the following Java Annotation: @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) public @interface Remote { Class[] value() default {}; } I only found this example for scala 2.7. In Scala 2.7, ...

What's the difference between these two calls to a function taking a collection of structural types?

Why does the call to fn(Iterator("foo") compile, but the call to fn(fooIterator) fail with an error "type mismatch; found : Iterator[java.lang.String] required: scala.Iterator[com.banshee.Qx.HasLength]" object Qx { type HasLength = {def length: Int} def fn(xs: Iterator[HasLength]) = 3 var tn = fn(Iterator("foo")) var...

@BeanProperty with PropertyChangeListener support?

@BeanProperty generates simple get/set methods. Is there a way to automatically generate such methods with support for firing property change events (e.g. I want to use it with JFace Databinding?) ...

Stable Scala 2.8 plugin

Does anyone know if there exists a stable version of the Scala plugin for eclipse, running with Scala 2.8 (any version of scala 2.8...RC or beta or whatever). I like the fact that it compiles 10 times faster than the netbeans plugin, but it is very unstable, and auto-imports doesnt work. Also, sometimes it cant find classes when I hit "...

Is there a good date/time API available for Scala?

I'm looking for something akin to JodaTime or JSR 310 for Scala that leverages nice Scala features such as operator overloading and doesn't rely on implicit conversions (I have an irrational fear of implicit conversions). I'm aware of http://github.com/jorgeortiz85/scala-time, but it just pimps JodaTime with implicits. ...

Accessing a Class Member from a First-Class Function

I have a case class which takes a list of functions: case class A(q:Double, r:Double, s:Double, l:List[(Double)=>Double]) I have over 20 functions defined. Some of these functions have their own parameters, and some of them also use the q, r, and s values from the case class. Two examples are: def f1(w:Double) = (d:Double) => math....

Scala DSL, Object and infix notation

Hello guys, in Scala, if I want to implement a DSL, is there a way to do the following: I have an Object called "Draw" which contains the function def draw(d:Drawable) how can I make it so that I can import the Object and call it outside the object like: draw ball if ball extends the Drawable trait? The problem is that I want to u...

How do I exclude/rename some classes from import in Scala?

Language FAQ says import scala.collection.mutable.{_, Map => _, Set => _} should import all classes from package scala.collection.mutable, except Map and Set. But it gives me this error: error: '}' expected but ',' found. import scala.collection.mutable.{_, Map => _, Set => _} Is there still a way to do this? ...

Scala 2.8: type inference of anonymous functions as default parameters

In Scala 2.8.0 RC 2 this definition: def buttonGroup[T](values: Array[T], textProvider: T => String = (t: T => t.toString)) = ... gives the error message: not found: value t def buttonGroup[T](values: Array[T], textProvider: T => String = (_.toString)) = ... gives missing parameter type for expanded function ((x$1) =>...

Scala 2.8 weird type error

Types: def radioGroup[T](values: Array[T], textProvider: T => String)(setups:(RadioGroup[T] => Unit)*)(parent: Composite): RadioGroup[T] def label(setups:(Label => Unit)*)(parent:Composite): Label def contains(setups : (Composite => Unit)*) : Composite // "Pimp my library" on Composite This works: new Composite(parent, SWT.NONE).c...

Does anyone have any recommendations for learning about Scala 2.8 changes?

Up until now I've been using Scala 2.7.7 (with Programming in Scala as my main reference). But as I'm a relative n00b, and 2.8 seems as if it will be out soon, I thought it would be a good idea to start using 2.8 before I get into any bad/outdated habits. I've seen http://www.scala-lang.org/node/1564 as a list of key new features, but d...