scala

Scala way to change this into a list?

Assume I have a routine which takes an enumeration value as an argument and returns a Boolean ... and I want to check a set of those enumeration values to see if they are all true. Is there a idiomatic way to do it. This was my "old school" attempt which seems non-scala-ish: def allUnitQueuesEmpty(): Boolean = ( getQueue(QID.CPU)....

Early return from a Scala constructor

I am writing the constructor for my "main" class. The first thing it does is call a method to use commons-cli to parse the command line. If the parseOptions method returns false, an error has occurred, and the constructor should exit. I tried writing the following code if (!parseOptions(args)) return but the compiler complains that I...

Can I overload paranthesis in Scala?

Trying to figure out out how to overload parenthesis on a class. I have this code: class App(values: Map[String,String]) { // do stuff } I would like to be able to access the values Map this way: var a = new App(Map("1" -> "2")) a("1") // same as a.values("1") Is this possible? ...

Is it possible to define companion classes/modules in the Scala interpreter?

It's often convenient to test things out in the Scala interpreter. However, one issue I run into is that I have to restructure code that uses implicit conversions because defining an object with the same name as an existing class does not make it a companion module in the REPL. As a result, I can't be confident my code will still work ...

Purpose of Scala's Symbol?

Possible Duplicate: What are some example use cases for symbol literals in Scala? What's the purpose of Symbol and why does it deserve some special literal synatx e. g. 'FooSymbol? ...

Scala classes in clojure

Hi It's just a stupid question that I had this morning : Can we use Scala classes from clojure ? Because if the answer is yes, I'll definetly learn Clojure ^^ ...

Environment for java + scala + lift project in eclipse without maven

I'm trying to understand what's the best way to setup a project that is a mix of java and scala and that will use lift. Lift is intended to run embedded by jetty in another application. I'm comfortable to work in Eclipse and also used to how it works with ant as build tool. I'm a relatively newbie in both scala and lift and get confused...

Nested Scala singletons from Java code

I have the following Scala (2.8) code: object A { val message = "hello" object B { val message = "world" } } And a similar Java class: public class C { public static String message() { return "HELLO"; } public static class D { public static String message() { return "WORLD"; } } } These work as I...

Including scala-library.jar in Maven generated package

I'd like to use Maven to include all the dependencies needed to run any Scala programs I write. I imagine this would mean at least scala-library.jar as well as any libraries I may use. I don't mind where these dependencies are stored (inside the generated JAR or outside), I'm just looking for a solution that sets up stuff like the manif...

How to write parser for unified diff syntax

Should I use RegexParsers, StandardTokenParsers or are these suitable at all for parsing this kind of syntax? Example of the syntax can be found from here. ...

lazy function definitions in scala

I've been learning scala and I gotta say that it's a really cool language. I especially like its pattern matching capabilities and function literals but I come from a javascript, ruby background and one of my favorite patterns in those languages is the lazy function and method definition pattern. An example in javascript is var foo = fu...

Using Lift 2.1 on Google App Engine with Scala 2.8

Hi, I'm trying to use Lift 2.1-SNAPSHOT on Google App Engine but the lift snippets in the HTML are not being processed. It simple returns the HTML file. This is the lift.html file (just a simple test): <lift:surround with="default" at="content"> Welcome to your Lift application </lift:surround> The web.xml has: <filter> <filt...

REST in lift 2.0 + Scala 2.8

I can see from release notes and such that there has been many improvements in lift 2.0 for building REST stuff, but I'm unable to find what has been done or how to use the new stuff compared to the old. Does anyone know of such documentation, blog entries, examples or similar for how to use REST in lift 2.0. Ideally I would like som...

Parsing a blank / whitespace with RegexParsers

What is the problem with parsing the blank/whitespace? scala> object BlankParser extends RegexParsers { def blank: Parser[Any] = " " def foo: Parser[Any] = "foo" } defined module BlankParser scala> BlankParser.parseAll(BlankParser.foo, "foo") res15: BlankParser.ParseResult[Any] = [1.4] parsed: foo scala> Blank...

Which cross platform scripting language should we adopt for a group of DBAs?

Hi there, I wanted to get the community's feedback on a language choice our team is looking to make in the near future. We are a software developer, and I work in a team of Oracle and SQL Server DBAs supporting a cross platform Java application which runs on Oracle Application Server. We have SQL Server and Oracle code bases, and supp...

Scala implicit type conversion and ==

Can anyone enlighten me as to why implicit type conversion does not work with ==? Example: class BitArray(l: Int, v: Long) { val length = l var value = v def ==(that: BitArray) = value == that.value def ==(integer: Long) = value == integer def +(that: BitArray) = new BitArray(length,value+that.value ) ...

retry connection to rate limited URL until successful in Scala

I need make a GET call to a REST api which is rate limited. I can find out what the current rate limit is by making a call and checking the HTTP headers. If I've exceeded my rate limit, I should wait for a bit before retrying. I'd like to write something like: val conn = connect(url, _.getHeaderField("X-RateLimit-Remaining").toInt > 0, ...

How to use Netbeans IDE 6.9 for Scala-Lift development? (i.e: setup, initial settings, workflows, etc)

I am thinking to try developing web using Scala-Lift framework. I have installed Scala 2.8, Netbeans 6.9, and Scala Plugin for Netbeans on my Ubuntu 10.04 machine. Since I am really new to Scala and Lift, I wonder if there are any good Scala-Lift getting-started tutorials specific to my development environment. Thanks you in advance. ...

Scala packrat parser

Hi, I have some questions about Packrat parser combinator presented in Scala 2.8. Unfortunatelly I wasn't able to find any tutorials of how to use this new feature except of Scaladoc PackratParsers trait description, which is rather short. Could it be possible to receive an example of using it? Actually, I have no experiance in Scala....

scala tuple unpacking

I know this question has come up many times in different ways. But it is still not clear to me. Is there a way to achieve the following. def foo(a:Int, b:Int) = {} foo(a,b) //right way to invoke foo foo(getParams) // is there a way to get this working without explicitly unpacking the tuple?? def getParams = { //Some calculations ...