scala

How to use property on Scala?

Yes, you can set a property name by setName and get it by getName. But what about property like this in C#: int Name{ get{return name;} set{name = value;} } or Name{get; set;} (auto property) I wonder if such thing exists in Scala. Googling around without any signals. ...

Perform bridge assignment in scala

I want to do this: var (a, b) = (0, 0) a = (b = 100) but Scala is complaining that error: type mismatch; found : Unit required: Int What I want is to assign a and b to the same value. Why Scala make it Unit where it should be Int? ...

How do I kill a RemoteActor?

Not sure whether I am missing something. When making an actor remote, the main method does not terminate. Here is a snippet that demonstrates the problem. import scala.actors._ import scala.actors.remote._ object TestMe { def main(args : Array[String]) : Unit = { object jim extends DaemonActor { // comment out th...

Scala abstract path dependent type problem

Does anyone know what's going on here with this compiler error? The error goes away if I don't extend INode. trait AbsTypes { type TKey type TValue } trait INode extends AbsTypes { def get(key : TKey) : TValue def set(key : TKey, v : TValue) : INode } class ANode[TKey,TValue]( val akey : TKey, val aval : TValue ) e...

How to reference subclasses of static Java classes with generics in Scala

I have this Java code: public class TestMapper extends AppEngineMapper<Key, Entity, NullWritable, NullWritable> { public TestMapper() { } // [... other overriden methods ...] @Override public void setup(Context context) { log.warning("Doing per-worker setup"); } } ...which I've converted to: class TestMa...

Scala abstract path dependent type problem part 2

Couple of questions on scala abstract types. Do I have to use parameterized [] types if I want to use the type in a constructor value? ie. is it possible to have a class with abstract constructor parameter types? If I get rid of [T1,T2] and use INode#TKey and INode#TValue as the constructor parameter types, what am I doing? I get confu...

which database to use in Scala (and examples needed)

I am new to Scala. Which database connectivity is best supported in Scala? I am also looking for complete examples to access a database (authenticate, connect, query, extract result) I have a table MyTable with two columns (Value1, Value2) in a database MyDB, which I need to access. I have been thinking of postgresql, so some example...

Why the "hello, world" is not output to the console? (Very newbie question)

I'm just learning scala, and I wrote the "hello,world" program like this: object HelloWorld { def main(args: Array[String]) { println("Hello, world!") } } I saved it to a file named "helloworld.scala" Now I run it in the console: scala helloworld.scala But nothing outputed. I thought it will output "Hello, world...

Scala: How to wait for a Actor/Reactor to be terminated

Hi there! I'm looking for some way to (busy) wait for an Actor (or Reactor) to be terminated, i.e. make sure that all messages sent before some Stop() message are consumed. What I came up so far with is setting up a CountDownLatch on which I can wait for the Stop() message to be processed. This approach seems to work, although I'm not ...

Finding info on scala operators

Im reading http://debasishg.blogspot.com/2008/04/external-dsls-made-easy-with-scala.html and I am trying to find info on the "<~" operator, for example: def trans = "(" ~> repsep(trans_spec, ",") <~ ")" I have some reasonable guess that has something to do with the product("~") operator along with lists? What does it do? In the futu...

scala new Range with step equals zero

Is(and why) this really should be prohibited with exception? scala> val r2 = 15 until (10, 0) java.lang.IllegalArgumentException: requirement failed scala> new Range(10,15,0) java.lang.IllegalArgumentException: requirement failed at scala.Predef$.require(Predef.scala:133) ...

What's a good and functional way to swap collection elements in Scala?

Hi! In a project of mine one common use case keeps coming up. At some point I've got a sorted collection of some kind (List, Seq, etc... doesn't matter) and one element of this collection. What I want to do is to swap the given element with it's following element (if this element exists) or at some times with the preceding element. I'm...

Confusion with a simple Scala packaging example

I've been experiencing confusion over packaging classes in Scala and importing packages. Let me start with a pair of simple source files: file: a/A.scala package a // Which of these imports should be used? They both seem to work. //import a.b._ import b._ class A { val fieldB = new B } file: a/b/B.scala package a.b class B u...

Convert String to Byte

Hi I need to convert a Char to an Byte. I belief this should be very simple but i don't find a nice solution. 0x7A.toChar => 'z' 'z'.???? => 0x7A Edit: I'm to tired... 'z'.toByte => 0x7A ...

scaladoc Ant task writing for multiple source directories?

I wish to compile scaladoc and javadoc in a project with both scala and java in it. The project has more than one source directory (each of which may have scala or javadoc). I tried: <scaladoc destdir="doc"> <classpath refid="compile.classpath"/> <src> <fileset dir="src"/> <fileset dir="tweetstream4j/src"/> ...

How to output {name} in xml of scala, not convert it?

val name = "mike" val xml = <name>{name}</name> xml will be <name>mike</name> But what if I want the xml be <name>{name}</name>, not convert the {name}? ...

Scala inheritance from Java class: select which super constructor to call

I have multiple constructor in a Java class. public class A{ public A(){...} public A(String param){...} public A(String param, Object value} } Now I want to create a Scala class that inherit from that class class B extends A{ super("abc") } But this syntax is invalid. Scala is complaining that '.' expected but '(' found. ...

How to output """ in the "here docs" of scala?

In scala, "here docs" is begin and end in 3 " val str = """Hi,everyone""" But what if the string contains the """? How to output Hi,"""everyone? ...

How to bind data in heredoc of scala?

val name = "mike" val str = """Hi, {name}!""" println(str) I want it output the str as Hi, mike!, but failed. How to do this? ...

String Array problem in Scala

Hi, I just started playing in scala. I got a method that accepts string array as input def Lambdatest(args:Array[String]) = args.foreach(arg=>println(arg)) And i have create a string array like this var arr=new Array[String](3) arr(0)="ram" arr(1)="sam" arr(2)="kam" When i call Lambdatest(arr), it throws an error like the below ...