scala-2.8

What are the limitations and walkarounds of Scala interpreter?

北慕城南 提交于 2019-12-05 14:05:36
What kind of constructs need 'scalac' compile and how to make an equivalent that will work in interpreter? Edit: I want to use scala instead of python as a scripting language. (with #!/usr/bin/scala) You ought to be able to do anything in the REPL that you can do in outside code. Keep in mind that: Things that refer to each other circularly need to be inside one block. So the following can't be entered as-is; you have to wrap it inside some other object: class C(i : Int) { def succ = C(i+1) } object C { def apply(i: Int) = new C(i) } The execution environment is somewhat different, so

@BeanProperty with PropertyChangeListener support?

拥有回忆 提交于 2019-12-05 12:58:27
@BeanProperty generates simple get / set methods. Is there a way to automatically generate such methods with support for firing property change events (e.g. I want to use it with JFace Databinding?) I've had the same question, and have been keeping a close eye out for possible answers. I think I've just stumbled across one (although I haven't tried it yet). Scala 2.9 has a feature for handling dynamic calls (meant for integration with dynamic languages, I suspect). Essentially, calls to methods which don't exist are routed to a method called applyDynamic. An implementation of that method could

Strange behavior: Scala Actors 2.7.7 vs. 2.8-Snapshot

不打扰是莪最后的温柔 提交于 2019-12-05 12:35:40
I'm an 18 years old trainee and I'm discovering scala which I like very much :-). To get familiar with the scala actors I wrote a small simulation with some gears and one controller. The ActorApplication creates N gears with random speed. The controller calculates a synchronization speed and starts the gear-actors. The gears synchronize to this given speed step by step (1+ or 1-). The simulation is finished when all gears have reached the synchronization speed. I developed the simulation in scala 2.7.7 - and it worked as I expected it (see output below). However, when I swichted to the current

Minimal framework in Scala for collections with inheriting return type

好久不见. 提交于 2019-12-05 12:04:28
问题 Suppose one wants to build a novel generic class, Novel[A] . This class will contain lots of useful methods--perhaps it is a type of collection--and therefore you want to subclass it. But you want the methods to return the type of the subclass, not the original type. In Scala 2.8, what is the minimal amount of work one has to do so that methods of that class will return the relevant subclass, not the original? For example, class Novel[A] /* What goes here? */ { /* Must you have stuff here? */

Scala, make my loop more functional

大兔子大兔子 提交于 2019-12-05 10:56:06
I'm trying to reduce the extent to which I write Scala (2.8) like Java. Here's a simplification of a problem I came across. Can you suggest improvements on my solutions that are "more functional"? Transform the map val inputMap = mutable.LinkedHashMap(1->'a',2->'a',3->'b',4->'z',5->'c') by discarding any entries with value 'z' and indexing the characters as they are encountered First try var outputMap = new mutable.HashMap[Char,Int]() var counter = 0 for(kvp <- inputMap){ val character = kvp._2 if(character !='z' && !outputMap.contains(character)){ outputMap += (character -> counter) counter +

How do I create an XML root node in Scala without a literal element name?

廉价感情. 提交于 2019-12-05 04:16:51
I'm looking to create a document like this: <root/> That I can add children to programatically. Theoretically, it would look like this: val root_node_name = "root" val doc = <{root_node_name}/> But that doesn't seem to work: error: not found: value < So, what I tried instead was this: val root_node_name = "root" val doc = new scala.xml.Elem(null, root_node_name, null, scala.xml.TopScope, null) That compiles but at runtime I get this null pointer exception: java.lang.NullPointerException at scala.xml.Utility$.toXML(Utility.scala:201) at scala.xml.Utility$$anonfun$sequenceToXML$2.apply(Utility

Strange behavior of Set4 in scala 2.9.1?

天大地大妈咪最大 提交于 2019-12-05 02:38:56
Making a migration from 2.8.1 to 2.9.1 found interesting thing. Tried to write this in console: >>import collection.immutable.Set.Set4 >>new Set4[Int](1,2,3,4) It gives: java.lang.Error: Unexpected New at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:34) at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$bac .......................... That entry seems to have slain the compiler. Shall I replayscala:660) your session? I can re-run each line except the last one.reach(ListBuffer.scala: [y/n]? I am using Scala version 2.9.1.final (Java HotSpot(TM) Client VM, Java 1.6

Scala collection type for filter

↘锁芯ラ 提交于 2019-12-04 22:32:50
Assume you have a List(1,"1") it is typed List[Any], which is of course correct and expected. Now if I map the list like this scala> List(1, "1") map { | case x: Int => x | case y: String => y.toInt | } the resulting type is List[Int] which is expected as well. My question is if there is an equivalent to map for filter because the following example will result in a List[Any]. Is this possible? I assume this could be solved at compile time and possibly not runtime? scala> List(1, "1") filter { | case x: Int => true | case _ => false | } Daniel C. Sobral Scala 2.9: scala> List(1, "1") collect {

Scala singleton factories and class constants

邮差的信 提交于 2019-12-04 21:58:37
OK, in the question about 'Class Variables as constants' , I get the fact that the constants are not available until after the 'official' constructor has been run (i.e. until you have an instance). BUT, what if I need the companion singleton to make calls on the class: object thing { val someConst = 42 def apply(x: Int) = new thing(x) } class thing(x: Int) { import thing.someConst val field = x * someConst override def toString = "val: " + field } If I create companion object first, the 'new thing(x)' (in the companion) causes an error. However, if I define the class first, the 'x * someConst'

how to use new scala 2.8.0 nested annotations

梦想与她 提交于 2019-12-04 21:02:30
问题 looks like when scala 2.8.0 is out, we can use nested @annotations in our persistence layers. But how? Can anyone please transform this from java to scala? Thanks. @NamedQueries({ @NamedQuery(name = "findAll", query="select p from Person p"), @NamedQuery(name = "findTheOne", query="select p from Person p where p.name = 'Neo'") }) 回答1: You have to wrap the elements in an Array() and write the nested annotations like a constructor call: @NamedQueries(Array( new NamedQuery(name = "findAll",