scala

What is are differences between Int and Integer in Scala?

I was working with a variable that I had declared as an Integer and discovered that > is not a member of Integer. Here's a simple example: scala> i warning: there were deprecation warnings; re-run with -deprecation for details res28: Integer = 3 scala> i > 3 <console>:6: error: value > is not a member of Integer i > 3 ^...

How should I organize implicits in my Scala application?

Having written a few scala tools, I'm trying to come to grips with the best way to arrange my code - particularly implicits. I have 2 goals: Sometimes, I want to be able to import just the implicits I ask for. Othertimes, I want to just import everything. To avoid duplicating the implicits, I've come up with this structure (similar t...

Scala immutable SortedSet are not "stable" on deletion

I've to deal with an immutable object in scala 2.7.5, and one of its member is an immutable Sortedset. I've no problem with addition, to synthetise, it gives: class MyClass[A](s:SortedSet[A]) { ... def + (elem:A):MyClass[A] { new MyClass(s + elem) } } And it works, since + operator is overload in trait sortedSet to return a...

How do I get started developing for a web using Scala?

Now, I am familiar with Scala language and ready to do web development. The only framework I came across is Lift and don't know anything about it. How do you approach web development using Scala? ...

Elements of Scala Style?

By day I write C#. Everything I do goes through Microsoft Code Analysis and Static Analysis tools so my C# has a very regular structure and layout. Obviously I write code with a certain style it partially because I have no choice (it won't compile if I miss out a space before that comma) but it's also nice to have regular looking code, k...

Scala closures on wikipedia

Found the following snippet on the Closure page on wikipedia //# Return a list of all books with at least 'threshold' copies sold. def bestSellingBooks(threshold: Int) = bookList.filter(book => book.sales >= threshold) //# or def bestSellingBooks(threshold: Int) = bookList.filter(_.sales >= threshold) Correct me if I'm wrong, but this...

Scala: What is the difference between while(true) and loop?

I don't get the actual (semantic) difference between the two "expressions". It is said "loop" fits to "react" and "while(true)" to "receive", because "react" does not return and "loop" is a function which calls the body again all over again (it least this is what I deduct from the sources - I am not really familiar with the used "andThen...

Scala equivalent to Haskell's where-clauses?

Is it possible to use something similar to where-clauses in Scala? Maybe there is some trick I didn't think of? Edit: Thanks for all your answers, they are very much appreciated. To sum up: Local vars, vals and defs can be used to achieve almost the same thing. For lazy evaluation, one can use lazy val (with implicit caching) or functi...

Read entire file in Scala?

What's a simple and canonical way to read an entire file into memory in Scala? (Ideally, with control over character encoding.) The best I can come up with is: scala.io.Source.fromPath("file.txt").getLines.reduceLeft(_+_) or am I supposed to use one of Java's god-awful idioms, the best of which (without using an external library) se...

Drawbacks to using Lift (Scala-based framework) for webservices?

I have been working on a project and as I have just started on the webservice I found Lift has been released, so I am curious if there will be much more complication by using Lift over Jax-WS using JDK6. I am doing this with the Eclipse IDE, but I don't know if I will get much benefit from the IDE on this project. ...

How to get Scala plugin and AJDT to be installed in same Eclipse

I get an error when trying to install both AJDT and Scala 2.7.5 plugin into Eclipse 3.5. I remember seeing a message at one point that there was a known problem with the two being installed, and the solution was to install a pre-release version of Scala plugin, from May I believe, then install AJDT. But, I don't remember which version ...

How to use SBT (Simple Build Tool) with Google App Engine?

Has anybody tried to setup SBT to work with Google App Engine? I dream about using development server auto-reloading after source changes. ...

Infix operators in Scala and Jython

I'm evaluating languages for a computational oriented app that needs an easy embedded scripting language for end users. I have been thinking of using Scala as the main underlying language and Jython for the scripting interface. An appeal of Scala is that I can define methods such as :* for elementwise multiplication of a matrix object a...

How should I think about Scala's Product classes?

The package "scala" has a number of classes named Product, Product1, Product2, and so on, up to Product22. The descriptions of these classes are surely precise. For example: Product4 is a cartesian product of 4 components Precise, yes. Communicative? Not so much. I expect that this is the perfect wording for someone who already under...

How to instantiate an instance of type represented by type parameter in Scala

example: import scala.actors._ import Actor._ class BalanceActor[T <: Actor] extends Actor { val workers: Int = 10 private lazy val actors = new Array[T](workers) override def start() = { for (i <- 0 to (workers - 1)) { // error below: classtype required but T found actors(i) = new T acto...

Scala: Mutable vs. Immutable Object Performance - OutOfMemoryError

I wanted to compare the performance characteristics of immutable.Map and mutable.Map in Scala for a similar operation (namely, merging many maps into a single one. See this question). I have what appear to be similar implementations for both mutable and immutable maps (see below). As a test, I generated a List containing 1,000,000 s...

Writing applications with Scala actors in practice

I've now written a few applications using scala actors and I'm interested in how people have approached or dealt with some of the problems I've encountered. A plethora of Message classes or !? I have an actor which reacts to a user operation and must cause something to happen. Let's say it reacts to a message UserRequestsX(id). A conti...

Writing applications with Scala actors in practice II

Because my first question was so long, I'm asking this as a separate question. It's another one about the architecture of an actor-based application. Keeping track of message paths through an Application Let's take a piece of Java code: public void deleteTrades(User user, Date date) { PermissionSet ps = permissionService.findPermi...

Is there a scala version of Python's Mechanize?

I have used mechanize in Python with great success. However, I am trying to learn Scala. I have an IRC bot that I would like to add some features to, mostly having to do with screen scraping web pages from our corporate intranet. That requires being redirected to a corp-wide login page, then going to the destination, then having to po...

Thread.join not behaving as I expected in scala

In the code below I create 20 threads, have them each print out a message, sleep, and print another message. I start the threads in my main thread and then join all of the threads as well. I would expect the "all done" message to only be printed after all of the threads have finished. Yet "all done" gets printed before all the threads...