scala

Stuck with JVM, Sick of Java... Where to go?

For the next 3 years I will have to work with the JVM (project requirement) using a very specific third party API. They want Java but I've been given leeway to move away from Java. I was hoping we could move back to the .NET framework so I could develop code in F#, being absolutely in love with OCaml. .NET development has been struck ...

Find all nodes that have an attribute that matches a certain value with scala

Hi, I saw the following example on Nabble, where the goal was to return all nodes that contain an attribute with an id of X that contains a value Y: //find all nodes with an attribute "class" that contains the value "test" val xml = XML.loadString( """<div> <span class="test">hello</span> <div class="test"><p>hello</p></div> </div>""" )...

Can you return an unevaluated function in scala?

Given this code: def getFunc(funcName:String, param:Int) = match funcName { case "FooFunc" => FooFunc(param) [...] } def FooFunc(param:Int) = param + SomeObject.SomeVariable How could I return FooFunc with param applied, without evaluating it? The reason I'd want to do this is because FooFunc, as you can see, relies on an externa...

Why does Scala implicitly convert Char to Int?

Looking at scala's Predef object, which is automatically imported, I found the following gem implicit def char2int(x : Char) : Int This has caused some sleazy bugs to sneak into my code (used _1 instead of _2 in Map[Char,Int]). I really don't get it, why would I want to implicitly convert Char to Int. The whole idea of having the Char...

How do I get Scala to run as a servlet under Tomcat?

I'm trying to build a basic servlet with scala, but I can't seem to figure out how to get it running under tomcat. I think my scala class is okay, and I included all the libs in scala-2.6.x-final-blah.tgz to my tomcat lib directory, but I still get the odd, generic error below. Can anyone tell me what's going on? javax.servlet.ServletE...

List of Scala's "magic" functions

Where can I find a list of scala's "magic" functions, such as apply, unapply, update, += etc? By magic-functions I mean functions which are used by some syntactic sugar of the compiler, for example o.update(x,y) <=> o(x) = y I googled for some combination of scala magic and synonyms of functions but didn't find anything. update: I th...

Scala and Tomcat -> NoClassDefFound Stringbuilder?

Hi, when I run my scala application under tomcat, I am unable to do basic string concatenation, and I get an error stating that no class definition was found for StringBuilder. I'm running under windows 7 (development) and ubuntu (production), and I don't believe that java 1.4.x JDK or JRE has ever been insalled on either system. Any id...

scala - Getting a read-only sublist view of a List

I would like a List, Seq, or even an Iterable that is a read-only view of a part of a List, in my specific case, the view will always start at the first element. List.slice, is O(n) as is filter. Is there anyway of doing better than this - I don't need any operations like +, - etc. Just apply, map, flatMap, etc to provide for list co...

How to set up sh script to be ran with Terminal (mac os) by default?

Hi all! I have a sh script (scala compiler). I'm trying to run it from Terminal application: sudo fsc, but it says that the file can't be found. I've set chmod +x, so script should be visible. It's sh script, not bash. Is it any possible? UPD: thanks all for the great answers, i really did learn a lot :) to set up Path properly, every...

Is there a built-in more elegant way of filtering-and-mapping a collection by element type?

If I want to narrow, say, an Iterable[A] for all elements of a particular type (e.g. String) I can do: as filter { _.isInstanceOf[String] } However, it's obviously desirable to use this as an Iterable[String] which can be done via a map: as filter { _.isInstanceOf[String] } map { _.asInstanceOf[String] } Which is pretty ugly. Of co...

How to handle XML Character reference in scala?

I am trying to generate some XML on-the-fly in Scala. I want to use a numeric character reference inside the XML and write out the resultant XML to an output stream. Example: val myXml = <body>Hello&#8198;World</body> val writer = new java.io.FileWriter("test") scala.xml.XML.write(writer, myXml, "utf-8", false, null) 8198 is unicode...

What Scala web-frameworks are available?

Hello! I've just started learning Scala and the first thing I'm going to implement is a tiny web-application. I've been using Erlang for the last year to implement server-side software, but I've never wrote web-applications before. It will be a great experience. Here is my question: are there web-frameworks for Scala except for Lift? ...

How do I setup multiple type bounds in Scala?

I want to be able to declare something like this: trait Narrowable[A] extends Iterable[A] { def narrow[B <: A & B <: AnyRef] : Iterable[B] } That it, the type B should be both a subtype of A and AnyRef. Is this possible? ...

Scala in java code : $colon

Hi, I read some java source code which including Scala source code. I found Nil.$colon$colon(Object arg) What does keywords $colon mean? And what does this line mean? ...

Hibernate and Scala

I have been toying with Scala and I was wondering if anyone had had any experience with using hibernate and mysql as a persistent store for scala objects? Does it work out of the box or is there a lot to do? ...

How to do something like this in Scala?

Sorry for the lack of a descriptive title; I couldn't think of anything better. Edit it if you think of one. Let's say I have two Lists of Objects, and they are always changing. They need to remain as separate lists, but many operations have to be done on both of them. This leads me to doing stuff like: //assuming A and B are the lists...

Using Scala as a scripting language from Eclipse

Is there a way to execute a scala script from Eclipse with scala plugin? A scala script is a scala file which is executed line by line, without forcing you to write a main method. See the Description section in scala's man page. ...

On Performance and Java Interoperability: Clojure vs. Scala

I have already read various accounts of Clojure vs. Scala and while I realize that both have their place. There are a few considerations that I haven't acquired a complete explanation on when it comes to comparing both Clojure with Scala: 1.) Which of the two languages is generally faster? I realize that this will vary from one langua...

Partitioning an Iterator in scala 2.7.5

It looks as though there is no partition method on an Iterator in scala 2.7.5 (there is in 2.8). I'd like to have a partition without losing the laziness of the Iterator, so the following is not an option: itr.toList.partition( someTest(_) ) Can anyone recommend a way of doing this without implementing my own partition method? For exa...

Please suggest direction for my small scala project

As a academic project of 6 months in college me and my 3 friends are going to implement "Distributed Caching" in scala language. Being new to both of these concepts and this being our first project I would be really happy if you guys could provide some direction. I am currently learning scala. Please let me know which particular features...