scala-2.8

RemoteActor.select - result deterministic?

a 夏天 提交于 2019-12-04 19:56:49
I wonder if there is any determinism when calling val delegate = RemoteActor.select(). I'm asking this, because I noticed that the program doesn't terminate, when I'm sending delegates over the net. Are there any other side effects, which depend on the delegate? Are there any rules, when RemoteActor.select will return the same delegate for the same arguments? Here's some example code which demonstrates the RemoteActor.select problem: package test import scala.actors.Actor, Actor._ import scala.actors.remote._, RemoteActor._ object DelegateTest { def main(args :Array[String]) { val actor = new

Targeting Android with Scala 2.8 Trunk builds

情到浓时终转凉″ 提交于 2019-12-04 16:35:44
问题 The definitive reference for using Scala on android seems to be here: http://www.scala-lang.org/node/160 Unfortunately, all the references on using scala with android are based around Scala 2.7 and refer to a custom build android-library.jar, with a couple of cryptic references suggesting that this custom build isn't needed for later versions of android (I'm using 2.1 / API v7) So... What are the steps needed to use Scala 2.8 in an android project? Preferably using eclipse and the Android

In Scala 2.8 collections, why was the Traversable type added above Iterable?

本秂侑毒 提交于 2019-12-04 15:47:00
问题 I know that to be Traversable , you need only have a foreach method. Iterable requires an iterator method. Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically silent on the subject of why Traversable was added. The SID only says "David McIver... proposed Traversable as a generalization of Iterable." I have vaguely gathered from discussions on IRC that it has to do with reclaiming resources when traversal of a collection terminates? The following is

What compromises Scala made to run on JVM?

此生再无相见时 提交于 2019-12-04 15:39:14
问题 Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice? 回答1: This article is a discussion with Martin Odersky (Scala's creator) and includes the compromises that were made in Scala for compatibility with Java. The article mentions: Static overloading of methods Having both traits and classes Inclusion of null pointers. 回答2: The two most important compromises I know about are: type erasure (

RemoteActor unregister actor

倾然丶 夕夏残阳落幕 提交于 2019-12-04 12:15:24
I'm playing with RemoteActors. Now I wonder, what happens if I shut down an RemoteActor. The actor was made available with RemoteActor.alive and RemoteActor.register. I can't find the inverse of either of both: alive and register. How do I properly shut down an RemoteActor? Update To make it more obvious, I made a 'small' example. Neither of the following 2 programs terminate, the JVM keeps running. All user created actors and main are finished. package test import scala.actors.{OutputChannel, AbstractActor, Actor} , Actor._ import scala.actors.remote.RemoteActor , RemoteActor._ object

What is the difference between a view and a stream?

醉酒当歌 提交于 2019-12-04 08:05:15
问题 In the Scala 2.8 collections framework, what is the difference between view and toStream ? 回答1: In a view elements are recomputed each time they are accessed. In a stream elements are retained as they are evaluated. For example: val doubled = List(1,2,3,4,5,6,7,8,9,10).view.map(_*2) println(doubled.mkString(" ")) println(doubled.mkString(" ")) will re-evaluate the map for each element twice. Once for the first println, and again for the second. In contrast val doubled = List(1,2,3,4,5,6,7,8,9

scala way to define functions accepting a List of different numeric types

不想你离开。 提交于 2019-12-04 06:30:48
I have the following problem: I have a function which takes a List[Double] as parameter, performs some arithmetic operations on the elements of the list and than return the result. I would like the function also to accept List[Int]. Here is an example: def f(l: List[Double]) = { var s = 0.0 for (i <- l) s += i s } val l1 = List(1.0, 2.0, 3.0) val l2 = List(1, 2, 3) println(f(l1)) println(f(l2)) Of course the second println fails since f requires List[Double] and not List[Int]. Also note the non scala style formulation of the sum within the f function in order to evidence the need to use 0 (or

Compile String to AST inside CompilerPlugin?

跟風遠走 提交于 2019-12-04 05:56:25
I would like to create a templating plugin and as the first step convert an arbitrary string to it's "compiled" AST representation (as the scala interpreter does, I guess). So a compiler plugin could e.g assign someString to "HELLO WORLD": @StringAnnotation("""("hello world").toString.toUpperCase""") var someString = "" My current first shot plugin does in short: runafter parser create a new representation only compiler and a VirtualFile with the annotation content compile and print unit.body see: http://paste.pocoo.org/show/326025/ a) Right now, "object o{val x = 0}" returns an AST, but e.g.

Covariant Typeparameter in scala needs to be invariant in java interface

夙愿已清 提交于 2019-12-04 00:53:19
I've got a trait that looks like this (some further information can be found at this related question by myself although I don't think, it's needed for this question) trait Extractor[-A,+B] { def extract(d:A):B //lots of other things } To use this in an existing java framework I would like this Extractor to either have a function that returns a Comparator[B] (being java.util.Comparator ) or even better extend Comparator[A] . Now that poses a problem because Comparator s type parameter is ought to be invariant, while A is contravariant and B is covariant. So I get errors like this: scala>

How to read from zipped xml files in Scala code?

自闭症网瘾萝莉.ら 提交于 2019-12-03 17:43:11
问题 How do I access XML data files directly from a zipped file in my Scala program? Are there any direct ways to programmatically unzip and read contents in my Scala code? 回答1: Here are a couple of ways of doing it in 2.8.1: cat > root.xml << EOF <ROOT> <id>123</id> </ROOT> EOF zip root root.xml and then in the REPL: val rootzip = new java.util.zip.ZipFile("root.zip") import collection.JavaConverters._ val entries = rootzip.entries.asScala entries foreach { e => val x = scala.xml.XML.load(rootzip