A newbie scala/lift question:
I checked out the CalendarMonthView sample:
http://scala-tools.org/mvnsites/liftweb-1.0/lift-widgets/scaladocs/net/liftweb/widgets/calendars/CalendarMonthView.html
with Lift 1.1-M6 and it compiled and worked.
When i tried to migrate the sample to Lift 1.1-SNAPSHOT the signature of AnonFunc seems to have ...
Let's say I have this method:
def myMethod(value:File,x: (a:File) => Unit) = {
// some processing here
// more processing
x(value)
}
I know I can call this as:
myMethod(new File("c:/"),(x:File) => println(x))
Is there a way I could call it using braces? Something like:
myMethod(new File("c:/"),{ (x:File) =>
if(x.toSt...
The following Scala code fails to compile in Scala 2.7.7, with a type mismatch error "found: Null(null) required: T" on the last line:
/**
* @param [T] key type
*/
class Key[T]
class Entry[T](val k: Key[T], val v: T)
def makeEntry[T <: AnyRef] = new Entry[T](new Key[T], null)
I'm fully aware of the evilness of nulls, but suffice ...
I would like a form a list of what nagging things of Java are history and by what feature of Scala has it been replaced.
I must admit I am new to Scala, so I cannot contribute much. But I feel, this list will be helpful for me as well as others to fully appreciate Scala
For e.g. we use keyword "val" and this makes the value immutable a...
Suppose I have this:
class String2(val x:String) {
def *(times:Int) : String = {
val builder = new StringBuilder()
for( i <- 0 until times) {
builder.append(x)
}
builder.toString()
}
}
now if I add this implicit:
implicit def gimmeString2(y:String) = new String2(y)
I will get a co...
In java I sometimes use class variables to assign an unique id to each new instances. I do something like:
public class Foo {
private static long nextId = 0;
public final long id;
public Foo() {
id = nextId;
nextId++;
}
[...]
}
How can I reproduce this behaviour in scala ?
...
In Scala, how does one define a local parameter in the primary constructor of a class that is not a data member and that, for example, serves only to initialize a data member in the base class?
For example, in the following code, how could I properly define parameter b in the primary constructor of class B so that it generates only a te...
Short of renaming the constructor parameter in the primary constructor of class B, what change can I make to the following code (without changing its function) so that Scala will compile it successfully?
Example:
class A(var a: Int)
class B(a: Int) extends A(a) {
def inc(value: Int) { this.a += value }
}
Error:
$ scala construct.s...
I am reading Scala and I am wondering ...
Why
val capacity : Int
instead of
val Int capacity.
Any reason why this choice was made. If not, it does not seem to me like a good choice to move away from the Java way of declaring it. Would have made the transition from Java to Scala easier (not by much, but little bit)
...
If I've writen a Scala program, can I compile it in a way so that anybody with a standard Sun Java JVM can run it? I guess the Scala compiler would have to include the Scala-specific API code in the compiled project? The reason I'm interested is that our class projects can usually be delivered in whatever language one prefers, but TAs gr...
I'm considering taking up scala programming but i'm really concerned about what will become of my ORM based applications. I currently use hibernate as my ORM and i find it a really reliable tool. I'd like to know if there's any ORM tool as efficient but written in scala, or will hibernate work seamlessly with it. i don't want to have to ...
Im trying to put together a simple ant build file for compiling a scala project (scala 2.7.6)...
I have everything working correctly except that its bringing up the
"fatal error: class java.lang.Object not found." both the scalac and scala libs are all in the project folder, so Im refering to them relativelly to the project root.
Im h...
The Scala homepage says that Scala 1.4 was runnable on the .NET framework - what is the status of Scala on the CLR now? Is anyone working on it? I think it would make a great GUI tool combined with GTK# and Mono...
...
I was wondering if there are any best practice guidelines on when to use case classes vs extending Enumeration in Scala. They seem to offer some of the same benefits.
...
Is there a Scala command-line debugger (a la jdb)?
...
I have a scala project that I use Maven and the maven-scala-plugin to compile. I need to include debug information in the compiled classes and I was wondering is there a way to ask Maven or the scala plugin to do this. I found this page that makes it sound possible but it's not clear where to put the params in the pom.xml.
If possible I...
I'm still a Scala noob, and this confuses me:
import java.util.regex._
object NumberMatcher {
def apply(x:String):Boolean = {
val pat = Pattern.compile("\\d+")
val matcher = pat.matcher(x)
return matcher.find
}
def unapply(x:String):Option[String] = {
val pat = Pattern.compile("\\d+")
val matcher = pat.matche...
I tried to create an unapply method to use in pattern matching, and I tried to make it return something different than Option, however, Eclipse shows that as an error. Is it a rule that unapply must return an Option[T] ?
EDIT: here's the code I'm trying to use. I switched the code from the previous section so that unapply returns a Bool...
As long as we have a PartialFunction[X,R] it's very easy to convert it to a function returning Option[R], e.g.
def pfToOptf[X, R](f: PartialFunction[X,R])(x: X) =
if (f.isDefinedAt(x)) Some(f(x))
else None
However, what if the task is opposite: suppose I have a function f getting X as an argument and returning Option[R] as a r...
I saw a delayed example in David Pollak's "Beginning Scala". I tried to adapt that, by trial and error. Here's what I have:
def sayhello() = {
println("hello")
}
def delaying(t: => Unit):Unit = {
println("before call")
t
println("after call")
}
delaying(sayhello())
How would you delay a function/method that takes parameters?...