def foo(x:Int, f:Unit=>Int) = println(f())
foo(2, {Unit => 3+4}
//case1
def loop:Int = 7
foo(2, loop) //does not compile
changing loop to
//case 2
def loop():Int = 7
foo(2, loop) // does not compile
changing loop to
//case 3
def loop(x:Unit): Int = 7 //changing according to Don's Comments
foo(2,loop) // compiles and works fine
sh...
Hey all,
I'm currently using SBT to manage my Lift project. I'd like to deploy it, but when I run 'sbt package' it produces a 60MB war file. This seems pretty large - are there ways I could cut down the size?
Thanks!
...
I am new to Scala, and ran across a small hiccup that has been annoying me.
Initializing two vars in parallel works great: var (x,y) = (1,2)
However I can't find a way to assign new values in parallel: (x,y) = (x+y,y-x) //invalid syntax
I end up writing something like this: val xtmp = x+y; y = x-y; x = xtmp
I realize writing function...
I've been using Scala 2.8RC1 and Scala Eclipse plugin for 2.8 RC1 happily for a few days. However, last night after adding a couple jar files to my environment (apache http client jars) the debugger just stopped stopping at breakpoints in scala code.
Java code stops fine at breakpoints. I tried creating a new mimimal scala app breakp...
Is there a Pattern in Scala that can add a method to an Array object?
I am thinking of the implicit conversion of Int to RichInt. But that can't be done as Array is a final class.
...
In the book "Programming in Scala" from Martin Odersky there is a simple example in the first chapter:
var capital = Map("US" -> "Washington", "France" -> "Paris")
capital += ("Japan" -> "Tokyo")
The second line can also be written as
capital = capital + ("Japan" -> "Tokyo")
I am curious about the += notation. In the class Map, I d...
I am starting a web app considering scalability as one of the top priorities.
What would be the benefits of this:
cassandra
scala
lift
vs the traditional LAMP
on the cloud? Since from what I've read, please correct me, the cloud itself is scalable
I have never seen anyone deploy scala on the cloud before. Is it worth the effort to lear...
Specifically, I'm saving a file upload to local file in a Lift web app.
...
When I run M-X ensime-disconnect I get the following forever:
string matching regex `\"((?:[^\"\\]|\\.)*)\"' expected but `^@' found
and I see this exception when I use C-c C-c
Uncaught exception in com.ensime.server.SocketHandler@769aba32
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Nat...
I am working in java and primarily Scala. I'm using the community edition of Intellij. I'm curious if its worth it to upgrade to the Ultimate Edition?
I've been back and forth with Intellij and Eclipse... and for Scala dev I like Intellij a little bit better (for now).
Thanks in advance...
...
I am new with Lift and want to know if it is developed to just run with Jetty but no other web server. Any idea?
...
Suppose I have the following Java file in a library:
package test;
public abstract class AbstractFoo {
protected static class FooHelper {
public FooHelper() {}
}
}
I would like to extend it from Scala:
package test2
import test.AbstractFoo
class Foo extends AbstractFoo {
new AbstractFoo.FooHelper()
}
I get an error, "...
In one of my first attempts to create functional code, I ran into a performance issue.
I started with a common task - multiply the elements of two arrays and sum up the results:
var first:Array[Float] ...
var second:Array[Float] ...
var sum=0f;
for(ix<-0 until first.length) sum += first(ix) * second(ix);
Here is how I reformed t...
Are there named constructors in Scala?
...
I tend to have this redundant naming in case classes:
abstract class MyTree
case class MyTreeNode (...)
case class MyTreeLeaf (...)
Isn't it possible to define Node and Leaf inside of MyTree?
What are best practices here?
...
I need something like this:
class Node (left : Node*, right : Node*)
I understand the ambiguity of this signature.
Is there a way around it better than the following?
class Node (left : Array[Node, right : Array[Node])
val n = new Node (Array(n1, n2), Array(n3))
Maybe some kind of separator like this?
val n = new Node (n1, n2, Se...
What is the difference between package and object?
...
Hi!
I would like to ask some kind of permission (I hope that doesn't sound strange) from the people who have influence on the naming conventions in modern languages like F#, Scala, etc.
My problem is - I just can't read camelCased code and wish I could write underscored_names at least in my internal implementations (not in API interfac...
I have a normal tree defined in Scala.
sealed abstract class Tree
object Tree {
case class Node (...) extends Tree
case class Leaf (...) extends Tree
}
Now I want to add a member variable to all nodes and leaves in the tree.
Is it possible with extend keyword or do I have to modify the tree classes by adding [T]?
Update:
It seems...
I have some class C:
class C (...) { ... }
I want to use it to index an efficient map. The most efficient map is an Array.
So I add a "global" "static" counter in companion object to give each object unique id:
object C {
var id_counter = 0
}
In primary constructor of C, with each creation of C I want to
remember global counter ...