I have been looking at type inference in Scala and there are a couple of things I'd like to understand a bit better around why expression/method-return types have to be explicitly declared in a few cases.
Explicit return declaration
Example (works if return keyword is ommitted):
def upCase(s: String) = {
if (s.length == 0)
retur...
I'd like to convert a piece of Java code which looks like the following into Scala:
for (Iterator<Task> it = tasks.iterator(); it.hasNext() && workflow.isAutoRun();) {
Task task = it.next();
if (!runTask(task)) break;
}
I am not a fan of the scala for-comprehensions (not that I know how to break the iteration anyway) and I've ...
I'm playing with scala's distributed actors. Very nice.
I have a server which executes incoming function objects.
For example, the client has
object Tasks {
def foo = {Console.println("I am Foo")};
def bar = {Console.println("I am Bar");}
}
// In client actor...
...
server ! Tasks.foo _
...
And the server can pick these up an...
I have the data for my webapp in a database that is accessed differently from different places. There is no generic code that can just do it for both. So I want to know at run time which env I am in. In fact, the code to run really depends on whether it is run within or without tomcat, so I would like to detect this at runtime. How d...
Hi,
I was browsing scala tests and I don't understand why the compiler produces a warning when you compare "two fresh objects".
This is the test' outputs:
http://lampsvn.epfl.ch/trac/scala/browser/scala/trunk/test/files/neg/checksensible.check
Example:
checksensible.scala:12: warning: comparing a fresh object using `!=' will always ...
How in Scala to find unique items in List?
...
I'm trying to modify the boot.scala in lift and running into a funny error. This is what I currently have:
val entries = Menu(Loc("Home", List("index"), "Home")) ::
Menu(Loc("StudentLogin", List("studentlogin"), "Student Login")) ::
Menu(Loc("ProviderLogin", List("providerlogin"), "Provider Login"))
LiftRules.setSiteMap(...
I'm using Scala's remote actors, but round-trip time (even of a trivial message) is 80ms, presumably due to underlying socket not having the TCP/IP Nagle algorithm disabled (also known as TCP_NODELAY), or at least that's what someone with some experience with Java RMI informs me.
All I'm doing in the client to get a link to the remote a...
Hi all-
I have this snippet:
class WelcomeSnippet{
def list (xhtml : NodeSeq) : NodeSeq = {
object sessionUserType extends SessionVar[String](null)
Helpers.bind("entry", xhtml, "edit" -> SHtml.link("/provider",() => sessionUserType("provider"), Text("Edit")))
}
}
I think its ok, but I keep getting this:
Not found:...
Why, in Scala, given:
a = List(1, 2, 3, 4)
def f(x : String) = { x }
does
a.map(_.toString)
work, but
a.map(f(_.toString))
give the error
missing parameter type for expanded function ((x$1) => x$1.toString)
...
While working with a Java class in Scala, I noticed that Scala can't multiply Java Doubles. Here's an example:
scala> val x:java.lang.Double = new java.lang.Double(34.0)
x: java.lang.Double = 34.0
scala> val y:java.lang.Double = new java.lang.Double(2.1)
y: java.lang.Double = 2.1
scala> x*y
<console>:7: error: value * is not a member...
Hi all-
I am trying to store a session variable and then use it to modify the menu in Boot.scala. Here is how I am storing the variable in a snippet:
object sessionUserType extends SessionVar[String](null)
def list (xhtml : NodeSeq) : NodeSeq = {
Helpers.bind("sendTo", xhtml,
"provider" -> SHtml.link("/provid...
Unlike Java, Scala lets you do a bare "try", without either a catch or finally clause:
scala> try { println("Foo") }
Foo
Does this actually have any meaning beyond,
{ println("Foo") }
?
...
Hi all-
I feel like I'm monopolizing the stack for Scala/Lift, so I apologize, but the questions keep coming. Here's the latest.
I'm trying to restrict access to anything in the /login/* to those users who have not yet logged in.
Here is how I'm trying to do it:
val entries = Menu(Loc("Home", List("index"), "Home")) :: //login stuff...
Hi,
I feel a bit insecure about using actors in Scala.
I have read documentation about how to do stuff..but I guess I would also need some DON'T rules in order to feel free to use them.
I think I am afraid that I will use them in a wrong way and I will not even notice it.
Can you think of something, that, if applied, would result in ...
Is it possible to inject a persistence context into a scala actor every time it acts? I have a dual Java/Scala spring application, and I am using spring annotations to markup my Java services and methods as transactional. I'd like to use similar functionality within my scala actors. That is, the actor should operate within a single tr...
I'm learning more about Scala and I'm having a little trouble understanding the example of anonymous functions here http://www.scala-lang.org/node/135. I've copied the entire code block below:
object CurryTest extends Application {
def filter(xs: List[Int], p: Int => Boolean): List[Int] =
if (xs.isEmpty) xs
else if (p(xs.head)...
Can a scala program be running on a browser with disabled java plugin (as scala is compiled to a jvm bytecode)? In other words: is the jvm disabled provided the java browser plugin is disabled?
Or does Scala run server-side and I am confused?
...
This code
class Foo(str: String) {
val len = str.length
def getLen = len
def getStr = str}
will be compiled to
public class Foo implements ScalaObject
{
private final int len;
private final String str;
public Foo(String str)
{
this.str = str;
super();
len = str.length();
}
...
I'm using Java's java.util.date class in Scala and want to compare a date object and the current time. I know I can calculate the delta by using getTime():
(new java.util.Date()).getTime() - oldDate.getTime()
However, this just leaves me with a Long representing milliseconds. Is there any simpler, nicer way to get a time delta?
...