scala

Processing concurrently in Scala

As in my own answer to my own question, I have the situation whereby I am processing a large number of events which arrive on a queue. Each event is handled in exactly the same manner and each even can be handled independently of all other events. My program takes advantage of the Scala concurrency framework and many of the processes i...

Using varargs from Scala

I'm tearing my hair out trying to figure out how to do the following: def foo(msf: String, o: Any, os: Any*) = { println( String.format(msf, o :: List(os:_*)) ) } There's a reason why I have to declare the method with an o and an os Seq separately. Basically, I end up with the format method called with a single object parameter (o...

Mixing object-oriented and functional programming

What languages are available that promote both object-oriented and functional programming? I know that any language that supports first-class functions can be considered functional, but I'm looking for a syntax that's specifically targeted for both coding styles. Using such a language, I'm imagining isolating all state changes to a sing...

lift snippet help

Hi, im just starting with lift and scala and have a problem i dont realy understand. i have the folowing index.html <html> <head><title>title</title></head> <body> <table> <lift:Members.list> <tr> <td><m:nick/></td> </tr> </lift:Members.list> </table> </body> And the f...

Scala match decomposition on infix operator

I'm trying to understand the implementation of Lists in Scala. In particular I'm trying to get my head around how you can write match expressions using an infix operator, for example: a match { case Nil => "An empty list" case x :: Nil => "A list without a tail" case x :: xs => "A list with a tail" } How is the match expression ...

Aggregate list values in Scala

I am learning Scala and exploring some of the functional aspects of the language. Starting with a list of objects containing two parameters notional and currency, how can I aggregate the total notional per currency? //sample data val t1 = new Trade("T150310", 10000000, "GBP"); val t2 = new Trade("T150311", 10000000, "JPY"); val t3 = ne...

Can Scala survive without corporate backing?

I was wondering whether Scala will get the takeup it deserves without explicit corporate backing (I was thinking by Sun/Oracle but I suppose it could be someone else, such as Google). With Sun's recent decision not to include closures in JDK7, couldn't they put their weight behind Scala as the Java alternative for those wishing to have ...

Hidden features of Scala

What are the hidden features of Scala that every Scala developer should be aware of? One hidden feature per answer, please. ...

How to convert from from java.util.Map to a Scala Map

A Java API returns a java.util.Map<java.lang.String,java.lang.Boolean>;. I would like to put that into a Map[String,Boolean] So imagine we have: var scalaMap : Map[String,Boolean] = Map.empty val javaMap = new JavaClass().map() // Returns java.util.Map<java.lang.String,java.lang.Boolean> You can't do Map.empty ++ javaMap, because t...

MVC on Lift/Scala

Has anyone tried to do a scala/lift application using MVC instead of view-first? I know that you can create Controllers/views as: package test.test.test.view ... Lots of imports ... class MvcRocks extends LiftView { def dispatch = { case "rule" => ruleDispatch _ case "bar" => barDispatch _ } def barDispatch(): Box[NodeSe...

Scala's existential types

A bit more specific than this question, can someone tell me what is the difference between Scala's existential types and Java's wildcard, prefereably with some illustrative example? In everything I've seen so far, they seem to be pretty equivalent. Edit: A few references. Martin Odersky mentions them; Google's top hit for my question ...

Can Scala's Actor framework handle 10.000 actors without stack problems?

I want to do a multi-agent simulation containing about 10.000 agents (machine and product agents) using the Scala Actor framework. As I understand, if there are lots of actors passing messages around, can it run out of stack due the recursion? If so, how can I increase the stack sizes for the underlying worker threads? ...

Should my Scala actors' properties be marked @volatile?

In Scala, if I have a simple class as follows: val calc = actor { var sum = 0 loop { react { case Add(n) => sum += n case RequestSum => sender ! sum } } } Should my field sum be marked @volatile? Whilst the actor is logically single-threaded (i.e. the messages are processed sequentially), the...

Simultaneous Java and Scala development within the same project

I want to leverage the Scala's Actor Framework while I develop the user interface in the familiar Swing way. Is it possible to have a mixed Java - Scala project in Eclipse, NetBeans or any other IDE? ...

Type problems with native Java classes.

Hello, I have the following problem, maybe someone can help me (or explain, where my mistake is). Given are a trait and a class: trait TextAttr[T <: {def setText(s:String); def getText : String}] { val obj : T def txt_= (s:String) = obj.setText(s) def txt = obj.getText } class ScalaText { private var t = "" def setText(s:Str...

Dynamic languages - which one should I choose?

Dynamic languages are on the rise and there are plenty of them: e.g. Ruby, Groovy, Jython, Scala (static, but has the look and feel of a dynamic language) etc etc. My background is in Java SE and EE programming and I want to extend my knowledge into one of these dynamic languages to be better prepared for the future. But which dynamic l...

Why the following Scala code does not compile unless explicit type parameters are added?

object Test extends Application { // compiles: Map[Int, Value]( 0 -> KnownType(classOf[Object]), 1 -> UnknownValue()) // does not compile: Map( 0 -> KnownType(classOf[Object]), 1 -> UnknownValue()) } sealed trait Value { def getType: Option[Class[_]] } case class UnknownValue() extends Value { def getType = ...

Howto design a clock driven multi-agent simulation

I want to create a multi-agent simulation model for a real word manufacturing process to evaluate some dispatching rules. The simulation needs to produce event logs to evaluate time effect of the dispatching rules compared to the real manufacturing event logs. How can I incorporate the 'current simulation time' into this kind of multi-a...

Scala HMAC-SHA1 signing?

I was wondering if there would be a way to get a HMAC-SHA1 signature in scala without having to compile a java class with the code everyone use in java. Any ideas? ...

Why do I get a java.nio.BufferUnderflowException in this Scala

I was trying to do some scripting in Scala, to process some log files: scala> import io.Source import io.Source scala> import java.io.File import java.io.File scala> val f = new File(".") f: java.io.File = . scala> for (l <- f.listFiles) { | val src = Source.fromFile(l).getLines | println( (0 /: src) { (i, line) => i + 1 } ) |...