scala

How to get stack trace of an exception in Scala to print it?

In a program of mine I'd like to catch all exceptions and explicitly print them (to be able to proceed with finally while still seeing exceptions). So I've tried this: try { ... } catch { case ex : Exception => { println ("\n" + ex) println ("\n" + ex.getStackTrace + "\n") } } finally { ... } But this (using getSta...

Persisting Collections with Squeryl

How can I persist a collections field (e.g. List[String] or Set[Int]) with Squeryl? What's the best way to encode it such that Squeryl won't create an association table? ...

Scala pattern matching keep saying "match is not exhaustive!"

I want to leverage the warning that Scala issues when a matching is missing ("not exhaustive") - so that I don't forget one (I have dozens). The following simplified example shows my attempt: sealed case class MESSAGE() class SUCCESS_MESSAGE extends MESSAGE class FAILURE_MESSAGE extends MESSAGE def log(str: String, msgType: MESSAGE) { ...

Difference between this and self in self-type annotations?

In various Scala literature I see some self-type annotations using "this" and others using "self": trait A { this: B => ... } trait A { self: B => ... } Is there any real difference between using "this" or "self"? Does it matter at all what name you use? Is this just as valid? trait A { foo: B => ... } ...

substituting xml values programatically with scala

I'm writing a tool to update some xml files (pom.xml in this case) with scala because the effort it would take in java is significantly higher than (in theory) it is with scala. I can parse the xml file just fine, but I need to replace nodes in the existing xml and rewrite the result. for example: <dependency> <groupId>foo</groupId>...

Speed of scala's ant fsc task

Hello experts, I have an ant file I use to compile my scala project. I'm using fsc which works wonders to avoid the 2~3 seconds my core 2 needs to just load the compiler. My problem is: the ant fsc task does incur the same 2~3 seconds penalty, to the best of my knowledge. It is pretty annoying, because there is fsc specifically for this...

Advice on writing a rich Web UI to front a RESTful HTTP API

Hi all, I've been working on a set of RESTful HTTP services implemented using Restlet in Java. Those services are currently used by a proprietary desktop application running on Windows, and by other back-end services. My goal now is to design an Ajaxy user interface to these services that will run within the Web browser. I am aware of ...

General 'map' function for Scala tuples?

Hi, I would like to map the elements of a Scala tuple (or triple, ...) using a single function returning type R. The result should be a tuple (or triple, ...) with elements of type R. OK, if the elements of the tuple are from the same type, the mapping is not a problem: scala> implicit def t2mapper[A](t: (A,A)) = new { def map[R](f: A...

Uses for Scala continuations

How are people using continuations on a larger and smaller scale in Scala? Are any parts of the Scala standard library written in CPS? Are there any major performance penalties in using continuations? ...

traverse collection of type "Any" in Scala

I would like to traverse a collection resulting from the Scala JSON toolkit at github. The problem is that the JsonParser returns "Any" so I am wondering how I can avoid the following error: "Value foreach is not a member of Any". val json = Json.parse(urls) for(l <- json) {...} object Json { def parse(s: String): Any = (new JsonP...

Scala assigning vals

Why isn't it possible to have this: def main(args:Array[String]) { val whatever:String // have it uninitialized here if(someCondition) { whatever = "final value" // initialize it here } } I don't understand why this shouldn't be legal.I know that I can make it a var,but why do we have to initialize the val exactly when we ...

Scala Swing Components

I have a collection of ComboBox declared as below. val cmbAll = for (i <- 0 to 4) yield new ComboBox(List("---", "Single", "Double")) And I try to listen to one of it via listenTo(cmbAll(0).selection) However, I can't actually perform the reactions. reactions += { case SelectionChanged(`cmbAll(0)`) => /** action here **/ } All...

If I try to compare 2 joda-time DateTime values in Scala I get java.lang.NoClassDefFoundError. How to fix this?

Here's an example: import org.scala_tools.time.Imports._ ... val dt1 : DateTime = new DateTime ("2010-09-01T12:00Z") val dt2 : DateTime = new DateTime ("2010-10-01T12:10Z") println (dt1 < dt2) // This is the Main.scala:48 line mentioned in the stack trace below ... If I compile and run it, I get java.lang.NoClassDefFoundError: s...

Scala dotless call syntax with curried function

Update: detailed answer to the more general problem at http://stackoverflow.com/questions/1181533/what-are-the-precise-rules-for-when-you-can-omit-parenthesis-dots-braces-fu, thank you for the answers! The following works: scala> List(1,2,3) filter (_ > 1) reduceLeft(_ + _) res65: Int = 5 And also the following: scala> List(1,2,3)....

Scala - implicit conversion of Int to Numeric[Int]

I've created a class that can be parameterised by anything that can be converted to Numeric class Complex[T <% Numeric[T]] (val real : T, val imag : T) { //... complex number methods ... } Then elsewhere in the code I try: var myComplex = new Complex(0, 1) This raises a compilation error because (surprisingly) there's no implici...

How should I match a pattern in Scala?

Hello I need to do a pattern in Scala, this is a code: object Wykonaj{ val doctype = DocType("html", PublicID("-//W3C//DTD XHTML 1.0 Strict//EN","http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"), Nil) def main(args: Array[String]) { val theUrl = "http://axv.pl/rss/waluty.php" val xmlString = Source.fromURL(new URL(theUrl)).m...

Scala regular expression (xml parsing)

Hello, I'm parsing an xml file, that has nodes with text like this: <img src="someUrl1"> American Dollar 1USD | 2,8567 | sometext <img src="someUrl2"> Euro 1EUR | 3,9446 | sometext <img src="someUrl3"> Japanese Jen 100JPY | 3,4885 | sometext What I want to get is values like this: American Dollar, USD, 2,8576 Euro, EUR, 3,9446 Japan...

Apache Commons ZipArchiveOutputStream breaks upon adding Filenames with non ASCII Chars

I am using an org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream to add files coming from a Subversion repository. This works fine as long as I do not use German Umlauts (ä,ö,ü) or any other special characters in the filename. I am wondering what would be the fastest way to make it accept non ASCII chars? def zip(repo: SVN...

No strictfp in Scala - Workarounds?

Hi SO, I searched the web for it but could not find any hint how to enforce srictfp in Scala. There are some people complaining about it but real solutions cannot be found. There is a bugtracker entry about it which is almost two years old. As it seems there is no elegant fix for it on the way I'm looking for workarounds. My current Id...

Lift mapper afterCreate before afterSave

Hi, do you know why afterCreate methods are not invoked after creating the object? Look at this code: val c = Company.create println(">>> After create") c.save Which produces: c: com.subeli.officebook.model.Company = 0 >>> After create create packages create packages save packages The Company model looks like this: object Company...