scala

Composing actors

I've implemented a Listenable/Listener trait that can be added to Actors. I'm wondering if it's possible to attach this style of trait to an actor without it having to explicitly call the listenerHandler method? Also I was expecting to find this functionality in the Akka library. Am I missing something or is there some reason that Akka ...

Can I ignore invalid XML character using Scala's builtin xml handlers?

I have an xml file(from federal government's data.gov) which I'm trying to read with scala's xml handlers. val loadnode = scala.xml.XML.loadFile(filename) Apparently, there is an invalid xml character. Is there an option to just ignore invalid characters? or is my only option to clean it up first? org.xml.sax.SAXParseException: An ...

How can implicits with multiple inputs be used in Scala?

For example, how can I write an expression where the following is implicitly applied: implicit def intsToString(x: Int, y: Int) = "test" val s: String = ... //? Thanks ...

How to interpret scaladoc?

How does foldRight[B](B) from scaladoc match the actual call foldRight(0) args is an array of integers in string representation val elems = args map Integer.parseInt elems.foldRight(0) (_ + _) Scaladoc says: scala.Iterable.foldRight[B](B)((A, B) => B) : B Combines the elements of this list together using the binary function f, from ...

In Scala, can I override a concrete field containing a list and append something to it in the subclass?

Here's a simplification of the classes I have: trait RequiredThings { val requiredThings: Seq[String] } class SimpleCalculator with RequiredThings { val requiredThings = List("a", "b") } class ComplicatedCalculator extends SimpleCalculator with RequiredThings { self: SimpleCalculator => override val requiredThings:List[String]...

Slow Scala assert

We've been profiling our code recently and we've come across a few annoying hotspots. They're in the form assert(a == b, a + " is not equal to " + b) Because some of these asserts can be in code called a huge amount of times the string concat starts to add up. assert is defined as: def assert(assumption : Boolean, message : Any) = .....

Merging elements in a scala list

I'm trying to port the following Java snippet to Scala. It takes a list of MyColor objects and merges all of the ones that are within a delta of each other. It seems like a problem that could be solved elegantly using some of Scala's functional bits. Any tips? List<MyColor> mergedColors = ...; MyColor lastColor = null; for(Color aColor ...

Project Euler 7 Scala Problem

I was trying to solve Project Euler problem number 7 using scala 2.8 First solution implemented by me takes ~8 seconds def problem_7:Int = { var num = 17; var primes = new ArrayBuffer[Int](); primes += 2 primes += 3 primes += 5 primes += 7 primes += 11 primes += 13 while (primes.size < 10001){ ...

Straight Java/Groovy versus ETL tool (Talend/etc) - what libraries would you use?

Assume you have a small project which on the surface looks like a good match for an ETL tool like Talend. But assume further, that you have never used Talend and furthermore, you do not trust "visual programming" tools in general and would rather code everything the old fashioned way (text on a nice IDE!) with the help of an appropriate...

How to convert a scala.List to a java.util.List?

I'm trying to use some Scala code and am having a hard time figuring out how to convert the Scala lists into standard Java lists. Any ideas? ...

Concurrent program languages for Chat and Twitter-like Apps.

I need to create a simple Chat system like facebook chat and a twitter-like app. What is the best concurrent program languages in this case ? Erlang, Haskell, Scala or anything else ? Thanks ^_^ ...

Generic object load function for scala

I'm starting on a Scala application which uses Hibernate (JPA) on the back end. In order to load an object, I use this line of code: val addr = s.load(classOf[Address], addr_id).asInstanceOf[Address]; Needless to say, that's a little painful. I wrote a helper class which looks like this: import org.hibernate.Session class DataLoader...

How do I alias the scala setter method 'myvar_$eq(myval)' to something more pleasing when in java?

I've been converting some code from java to scala lately trying to teach myself the language. Suppose we have this scala class: class Person() { var name:String = "joebob" } Now I want to access it from java so I can't use dot-notation like I would if I was in scala. So I can get my var's contents by issuing: person = Person.new(...

How to access "overridden" inner class in Scala?

I have two traits, one extending the other, each with an inner class, one extending the other, with the same names: trait A { class X { def x() = doSomething() } } trait B extends A { class X extends super.X { override def x() = doSomethingElse() } } class C extends B { val x = new X() // here B.X i...

How do Scala parser combinators compare to Haskell's Parsec?

I have read that Haskell parser combinators (in Parsec) can parse context sensitive grammars. Is this also true for Scala parser combinators? If so, is this what the "into" (aka ">>") function is for? What are some strengths/weaknesses of Scala's implementation of parser combinators, vs Haskell's? Do they accept the same class of gra...

Don't understand the typing of Scala's delimited continuations (A @cps[B,C])

I'm struggling to understand what precisely does it mean when a value has type A @cps[B,C] and what types of this form should I assign to my values when using the delimited continuations facility. I've looked at some sources: http://lamp.epfl.ch/~rompf/continuations-icfp09.pdf http://www.scala-lang.org/node/2096 http://dcsobral.blogs...

Scala isn't allowing me to execute a batch file whose path contains spaces.Same Java code does.What gives?

Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= "cmd.exe" commandsBuffer ::= "/c" commandsBuffer ::= '"'+vcVarsAll.getAbsolutePath+'"' commandsBuffer ::= "&&" otherCommands.foreach(c => commandsBuffer ::= c) val asArray = commandsBuffer.reverse.toArray val processOutput = processutils.Proc.executeCommand(a...

scala 2.8 implict java collections conversions

I have problem with JavaConversions with 2.8 beta: import scala.collection.JavaConversions._ class Utils(dbFile : File, sep: String) extends IUtils { (...) def getFeatures() : java.util.List[String] = csv.attributes.toList } And then exception: [INFO] Utils.scala:20: error: type mismatch; [INFO] found : List[String] [IN...

Scala: Why are Actors lightweight?

Forgive me if this is a stupid question, but what makes actors so lightweight? To be honest, I'm not even sure how they work. Aren't they separate threads? 'Seems I have two questions. Thanks in advance :) ...

Is this the proper way to initialize null references in Scala?

Let's say I have a MyObject instance which is not initialized: var a:MyObject = null is this the proper way to initialize it to null? ...