I got a similar problem to this guy while processing 4MB log file. Actually I'm processing multiple files simultaneously but since I keep getting this exception, I decide to just test it for a single file:
val temp = Source.fromFile("./datasource/input.txt")
val dummy = new PrintWriter("test.txt")
var itr = 0
println("Default Buffer siz...
I can assign a tuple as follows:
var (min, max) = (1, 2)
But I cannot then re-assign as follows
(min, max) = (1, 3) //compiler error: ';' expected but '=' found
Instead I seem to have to do:
min = 1
max = 3
Why does the latter work whereas the former does not?
...
I've written a trivial scala program to open an XML file.
Is there a way to get scala to validate the XML file against the schema file that it references? Currently my XML file doesn't follow the schema, so I'd expect to get errors on validation.
The XML file references the schema like this in the root element:
<items xmlns:xsi="http:...
I have (global-set-key (kbd "RET") 'newline-and-indent) in my .emacs which works fine in all modes but scala-mode(the newest, revision 19295 from svn).
What do I need to change to get it working?
...
How to do testing and is there something similar like Rack::Test with ruby frameworks?
...
I'm trying to get a real equivalent for Java's public static final in Scala for using TwiP.
Creating a val in an object don't works for me, because it's part of a new generated class Example$.class and TwiP can't access it from class Example.class.
Here's an example of a Java Class I'm trying to port to Scala:
public static final Stri...
On 2.7.5.final, I'm attempting to add a Iterable list of Ints like so
def sum(xs: Iterable[Int]): Long = {
var sum = 0L
xs.foreach((x) => sum = sum + x)
sum
}
println(sum(List(1, Integer.MAX_VALUE - 1)))
println(sum(Integer.MAX_VALUE - 1 to Integer.MAX_VALUE))
println(0L + Integer.MAX_VALUE - 1 + Integer.MAX_VALUE)
When I run, ...
I'm trying to figure out how to instantiate a case class object with reflection. Is there any support for this? The closest I've come is looking at scala.reflect.Invocation, but this seems more for executing methods that are a part of an object.
case class MyClass(id:Long, name:String)
def instantiate[T](className:String)(args:Any*) ...
In the upcoming scala 2.8, a util.control package has been added which includes a break library and a construct for handling exceptions so that code which looks like:
type NFE = NumberFormatException
val arg = "1"
val maybeInt = try { Some(arg.toInt) } catch { case e: NFE => None }
Can be replaced with code like:
import util.control....
I'm trying to represent the result of an MD5 hash in the shortest possible string. It seems a waste to just turn it into a hex string and let G through Z go to waste.
One idea I have had is getting the MD5 hash of my input as an array of bytes and constructing a BigInt with it. I can then call toString(36), and get the number as a base-...
In Java, one would synchronize methods or blocks that access a shared resource that is needed in a multi-threaded environment.
I'm wondering how the "Scala Actors" way of doing this would work.
Suppose I have a connection pool of java.sql.Connection objects that I wish to provide thread-safe access to. I implement it as an actor that ...
Experimenting with Scala... I'm trying to define something analogous to the "@" hack in PHP (which means, ignore any exception in the following statement).
I managed to get a definition that works:
def ignoreException(f: () => Unit) = {
try {
f();
}
catch {
case e: Exception => println("exception ...
I'm working on a small MVC "framework" (it's really very small) in Scala. I'd like to be able to write my view files as Scala code so I can get lots of help from the compiler. Pre-compiling is great, but what I really want is a way to have the servlet container automatically compile certain files (my view files) on request so I don't hav...
Let's say I have some classes like this:
abstract class View(val writer: XMLStreamWriter) {
// Implementation
}
class TestView(writer: XMLStreamWriter) extends View(writer) {
// Implementation
}
Most subclasses of View are not going to take different constructor arguments. I would like to be able to write something like this:...
ArrayBuffer extends ResizableArray which include a protected method, swap. Yet I can't access swap. What am I missing?
scala> import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.ArrayBuffer
scala> val x=new ArrayBuffer[Int]()
x: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer()
scala> x+=3
scala> x+=5...
I'm new to Scala, and from what I understand yield in Scala is not like yield in C#, it is more like select.
Does Scala have something similar to C#'s yield? C#'s yield is great because it makes writing iterators very easy.
Update: here's a pseudo code example from C# I'd like to be able to implement in Scala:
public class Graph<T> {
...
I'm learning Scala and trying to use javax.cache in Scala code and can't find how to solve this problem:
val cacheFactory = CacheManager.getInstance.getCacheFactory
val map = new HashMap
val cache = cacheFactory.createCache(map)
def rawSet(key:String, value:Array[Byte]) {
cache.put(key, value)
}
and the compiler error is:
er...
I was experimenting with variable constructor arguments for case classes in Scala, but am unable to pass them to the constructor of a case classes' parent:
abstract case class Node(val blocks: (Node => Option[Node])*)
case class Root(val elementBlocks: (Node => Option[Node])*) extends Node(elementBlocks)
the above doesn't compile... i...
I have a recursive function that takes a Map as single parameter. It then adds new entries to that Map and calls itself with this larger Map. Please ignore the return values for now. The function isn't finished yet. Here's the code:
def breadthFirstHelper( found: Map[AIS_State,(Option[AIS_State], Int)] ): List[AIS_State] = {
val exten...
what is going on in each of these forms of defining foo?:
scala> def foo = {1}
foo: Int
scala> foo
res2: Int = 1
But:
scala> def foo {1}
foo: Unit
scala> foo
scala>
...