scala-2.10

Clean solution for dropping into REPL console in the middle of program execution

情到浓时终转凉″ 提交于 2019-12-04 17:47:22
问题 Is there any working solution for dropping into REPL console with for Scala 2.10? This is mainly for debugging purpose - I want to pause in the middle of execution, and have a REPL console where I can inspect values and test the program's logic using complex expressions within my program at the current state of execution. Those who have programmed in Ruby might know similar function: the binding.pry . AFAIK, Scala 2.9 and under used to have breakIf but it has been removed from the later

How can I get Scala ToolBox to see REPL definitions?

旧城冷巷雨未停 提交于 2019-12-04 17:40:33
问题 Back when reflection was still incipient, on the days of Scala 2.10.0 milestones, I asked a question about how could I use it to see the trees of code snippets from REPL. The excellent answer went further than I asked, and showed how they can be used to parse and evaluate trees as well, so I went ahead and tried to use that on a little project I had going on today. Unfortunately, code parsed and evaluated that way doesn't seem to see any REPL definition: scala> val x = 1 x: Int = 1 scala>

When using Scala futures, will chained callbacks with the same execution context be optimised into synchronous calls?

纵然是瞬间 提交于 2019-12-04 17:37:43
问题 The new Future in Scala 2.10 uses an execution context for every operation where an action is called asynchronously (including map , filter , etc). Does this mean that every action will always be called individually through the execution context, or is it possible that this step is optimized away when chaining multiple transformations/filters each using the same execution context? I.e. if doing f.map(...).filter(...).map(...) , all with the same execution context, will this call execute()

Implicit parameter and ClassTag

孤者浪人 提交于 2019-12-04 15:42:56
Can someone explain what the Scala compiler is trying to tell me with the error message below? object Some { def apply[T: ClassTag](data: T)(implicit ordering: Ordering[T]): T = data } object Other { def apply[T: ClassTag](data: T)(implicit ordering: Ordering[T]): T = Some(data)(ordering.reverse) } Compiler says: not enough arguments for method apply: (implicit evidence$2: scala.reflect.ClassTag[T], implicit ordering: Ordering[T])T in object Some. Unspecified value parameter ordering. The error arose when I added the ClassTag to the method in object Some , in order to use some internal arrays

How to get more information about 'feature' flag warning?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 09:59:09
问题 When compiling an application with Play2, sometimes these kind of message appears on my terminal : [info] Compiling 1 Scala source to ~/target/scala-2.10/classes... [warn] there were 1 feature warnings; re-run with -feature for details [warn] one warning found [success] Compiled in 1s How can I get more information about those warning? It must be an option of sbt but I have no idea where to search... 回答1: To see the exact message you need to add "feature" flag in your sbt build definition

How to build a dynamic sequence in a scala macro?

爱⌒轻易说出口 提交于 2019-12-04 09:48:17
I have a scala macro which outputs nested case classes. I can assemble fragments of expressions created using reify to build up the nested case classes programmatically: case class Foo(name: String) case class Bar(foo: Foo) def foo(name: String) = { c.universe reify { Foo(c.literal(name).splice) } } def bar(foo: Expr[Foo]) = { c.universe reify { Bar(foo.splice) } } // output Bar(Foo("MyFoo")) c.Expr( bar(foo("MyFoo").asInstanceOf[Expr[Foo]]).tree ) Things work well apart from the annoying cast (how can i fix that?). Where I am stuck is when I want the macro to output some case class which

What is the easiest way to update an immutable AST?

假装没事ソ 提交于 2019-12-04 07:17:10
While working with macros, I have reached the point (I have been trying hard to avoid it) where I need to update those nodes in the AST which hold certain condition. For instance, let's say I would like to update each node: Literal(Constant(1)) with the value: Literal(Constant(2)) Those AST nodes could be anywhere in the expression tree, so I cannot use an ad-hoc pattern matcher. Obviously, the last thing I would like to do is to code a full pattern matcher which is able to cover all the compiler primitives. I have been searching in the API but I have the impression that methods such as

F-Bounded polymorphism with abstract types in Scala

烈酒焚心 提交于 2019-12-04 07:11:35
I have read several articles expressing that abstract types should be used to achieve f-bounded polymorphism in Scala. This is primarily to alleviate type inference issues, but also to remove the quadratic growth that type parameters seem to introduce when defining recursive types. These are defined as so: trait EventSourced[E] { self => type FBound <: EventSourced[E] { type FBound <: self.FBound } def apply(event: E): FBound } However, this appears to introduce two issues: 1) Each time a user wants to reference an object of this type, they must also refer to the FBound type parameter. This

Can this free-term-variable error (produced at macro expansion) be avoided?

独自空忆成欢 提交于 2019-12-04 03:41:29
I am developing a DSL and I am getting a "free term" failure while expanding a macro. I would like to know if it can be avoided. I have simplified the problem to the following situation. Suppose we have this expression: val list = join { 0 1 2 3 } println(list) where join is a macro whose implementation is: def join(c: Ctx)(a: c.Expr[Int]): c.Expr[List[Int]] = { import c.mirror._ a.tree match { case Block(list, ret) => // c.reify(List(new c.Expr(list(0)).eval, // new c.Expr(list(1)).eval, // new c.Expr(list(2)).eval) :+ new c.Expr(ret).eval) c.reify((for (expr <- list) yield new c.Expr(expr)

Passing implicit ExecutionContext to contained objects/called methods

*爱你&永不变心* 提交于 2019-12-03 20:07:48
问题 I'm creating an async library using Scala 2.10 futures. The constructor for the library takes a sequence of user-defined objects that implement a certain trait, and then a method on the library class sends some data one-by-one into the user-defined objects. I want the user to provide the ExecutionContext for the async operations when setting up the main instance, and then for that context to get passed into the user-defined objects as necessary. Simplified (pseudo?)code: case class Response