scala

What are your experiences developing in Scala/Lift ?

I heard a lot of good things about Scala and the Lift Web framework recently, especially from Foursquare's guys hence, I might use this technology in my next projects. Are any of you Scala/Lift Developers? What have your experiences been for developing on this platform and what are its advantages over Ruby On Rails or Python/Django? ...

scala won't take a 12-digit integer

ok so I'm just getting started in scala.. ran into a weird problem with a large number. import Math._ var num:Long=0 num+=600851475 num*=1000 println(num) that code works fine, yet the following doesn't compile with an error saying the integer is too large. import Math._ var num:Long=0 num+=600851475000 println(num) what's up? can ...

In Scala or Java, how to get how much RAM does application currently occupy?

NetBeans IDE has a taskbar indicaror, showing how much RAM is currently allocated and used by the running instance. How can I get this data in my own application written in Scala? If there's no special function for this in Scala, I could use Java one. ...

In Scala 2.8, how to write (append) a line to a file? Should I use Java clesses or there are native Scala functions for this?

In Scala 2.8, how to write (append) a line to a file? Should I use Java clesses or there are native Scala functions for this? If you can also tell how to replace or remove a particular line from a text file - it'd be also interesting. ...

In Scala or Java, how to print a line to console replacing its previous content instead of appending?

A Scala application does some data processing. It would be nice to show processing progress in percents overwriting previous value on change rather than appending a new value to what's already displayed. How to acheive this effect? I use Scala 2.8 on Linux. ...

Can we define a higher-kinded type-level identity function in Scala?

In Scala we can define the type-level identity function for lower-kinded types like so, type Id[A] = A Can we also define something similar for higher-kinded types? Ie. can we fill in the blanks in, type HKId[A[...]] = ... so that something similar to HKId[List] gets us back to the List type constructor? Binding of free names in t...

What is the most elegant way to deal with an external library with internal state using a function programming language?

I'm currently playing around with Scala development, but I need to integrate with libraries such as box2d to handle physics. The problem is that this requires to depend on an external library which manages its own state. You keep track of the bodies which you pass into the box2d world. To sum up the aspects in play: Box2d manages the s...

Scala def versus val

val f1 = (a:Int) => a + 1 def f2 = (a:Int) => a + 1 def f3:(Int => Int) = a => a + 1 What's the difference? scala> f1 res38: (Int) => Int = <function1> scala> f2 res39: (Int) => Int = <function1> scala> f3 res40: (Int) => Int = <function1> ...

good example liftweb app using Google Map API?

Anyone know of any good examples of using Google Map API from within a scala liftweb app? ...

iterating over scala collections in java

How I can iterating over scala collections in java? ...

Scala: Using HashMap with a default value

I have a mutable HashMap and would like to use it like a default-dictionary. The obvious method appears to be to use getOrElse and provide the default value each time as a second value. However this seems a little inelegant in my use case since the default value doesn't change. var x = HashMap(1 -> "b", 2 -> "a", 3 -> "c") println(x.ge...

Scala actors thread control

Hello, I would like to know more about the extent it is possible to control where each Scala actor is running. I happen to be in a somewhat particular case : high reactivity is desired, a good part of the code is time-critical, and worst of all, I'm on Android. With this in mind, my main goal is : make the code as readable and straightf...

Find elements in a list that's not in the second list (in scala)

Suppose I have two lists: val a = List('a', 'b', 'c') val b = List('a', 'b', 'c', 'd') I want to get the element which is not in the first list (in this case it's 'd'). I know I can do this with a loop, but is there any fancy functional way to do this quickly in one line? I've been looking at the Scala List API, but could only found ...

SOAP-proxy in Scala - what do I need?

I'm trying to write a program in Scala, that will accept SOAP-requests, get the response from the real server (or read it from the local disc) and return the data to the original client. I'm new to the java/scala ecosystem, so I have no clue, what libraries to choose. I heard Scala's XML-handling is quite nice, so I don't know, whether ...

what's wrong with renaming imported static functions?

Consider the following Scala code: object MainObject { def main(args: Array[String]) { import Integer.{ parseInt => atoi } println(atoi("5")+2); println((args map atoi).foldLeft(0)(_ + _)); } First println works fine and outputs 7, but the second one, attempting to map array of strings ag...

How to cache results in scala?

This page has a description of Map's getOrElseUpdate usage method: object WithCache{ val cacheFun1 = collection.mutable.Map[Int, Int]() def fun1(i:Int) = i*i def catchedFun1(i:Int) = cacheFun1.getOrElseUpdate(i, fun1(i)) } So you can use catchedFun1 which will check if cacheFun1 contains key and return value associated with it. ...

Google App Engine + Scala2.8.0 + Lift 2, all ok, but doesn't work why?

I build a lift project with this command: mvn archetype:generate -U \ -DarchetypeGroupId=net.liftweb \ -DarchetypeArtifactId=lift-archetype-basic \ -DarchetypeVersion=2.0-scala280-SNAPSHOT \ -DarchetypeRepository=http://scala-tools.org/repo-snapshots \ -DremoteRepositories=http://scala-tools.org/repo-releases \ -DgroupId=dem...

Scala - Prefix Unary Operators

I've recently given Scala a second chance, and started with the project I always implement (in functional or pseudo-functional languages): an automated reasoner for propositional logic (and later predicate logic). Now, I've tried to get the notation of propositional logic in the language itself as pretty as possible, and I've gotten thi...

Scala: jaxb or similar?

As a java programmer I'm quite comfortable with using JAXB and similar, for example to construct object from a XML spec. I'm sure I can make JAXB work nice in scala, but I wonder if that is the scala way of doing it, or if there is some better/smarter way, especially since XML is almost part of the language / it's internal libraries. S...

Java/Scala bi-directional MD5

Hello, I am trying to find some samples of how to take a string and hash it using MD5, and then be able to reverse hash (correct term?) back to the original string. Does anyone know of any documentation that shows how this can be done, or ideally has any sample code they could share? I've read about the java.security.MessageDisgest cl...