我在type macros上寻找scala。但是当我想从示例中创建对象时,我得到了错误:
Example.scala:7: `=', `>:', or `<:' expected
type Test(url: String) = macro impl
Example.scala:12: illegal start of simple expression
val clazz = ClassDef(..., Template(..., generateCode()))
代码:
//Example.sbt
object Example {
type Te
我已经创建了一个简单的宏,如果当前日期被传递到指定的FIXME (或TODO)日期,它将生成编译器警告(或错误)。
Scala2.10.4的宏实现()使用了c.Expr[Any]返回类型,在2.11.0中它是一个返回c.Tree的白盒宏。
在这两种情况下,返回c.Expr[Any](EmptyTree)或EmptyTree分别返回一个值。假设以下宏调用,
def hi() {
FIXME("2073/04/10: This will abort compilation if not fixed by 2073/04/10")
println("hi")
我有一个scala.js项目。在这里,我对Scala.Meta和Binding.scala有一个奇怪的行为。
我想从一个案例类创建一个案例类:
case class SimpleCaseClass(i: Int, s: String, list: Seq[String])
应产生以下内容:
SimpleCaseClassFormData(Var[Int], Var[String], Vars[String])
一旦我有了一个Vars,我就会得到以下错误:
A method defined in a JavaScript raw type of a Scala.js library has be
我是Scala的新手,现在我经历了一个类似以下的构造: scala> var a = List(('a',1),('b',2)) 我用谷歌搜索了这个,结果是一个Scala tuple2。我的问题是: 这是一个特殊的Scala结构吗?也就是说,每当我使用('a',3)时,scala创建一个Tuple2,或者有什么配置可以让scala创建MyTuple2而不是Tuple2?我可以创建自己的类,让scala在我使用它的构造函数时使用它吗?
有没有办法做这样的事
scala> trait Foo { def f:Int=0 }
defined trait Foo
scala> class FooImpl extends Foo { override val f = 1 }
defined class FooImpl
scala> class Bar(foo:Foo) extends Foo{ import foo._ }
defined class Bar
scala> (new Bar(new FooImpl)).f
res2: Int = 0
scala> trait Foo { def
我对宏的以下行为完全感到困惑:
问题:--我正在为构建在case classes上的模型编写查询引擎,用户只需指定他希望匹配的字段。
当前的方法:--目前,我正在做一件懒散的事情,只是利用默认的Scala模式匹配,使用宏来创建适当的match语句。守则如下:
// This is the macro code, defined in project `macros`
import scala.reflect.macros.whitebox
object QueryEngineMacros {
import scala.language.experimental.macros
def
我有Intellij-IDEA 13.1.2。编辑的,以前的13.0.2我使用scala.我试图使用工作表来评估代码。
但我只有两个错误:
bad macro impl binding: versionFormat is supposed to be there
Unable to read an event from: rO0ABXNyADVvcmcuamV0YnJhaW5zLmpwcy5pbmNyZW1lbnRhbC...
我可以正常运行scala控制台并在其中执行我的代码,但是工作表不起作用。如果我的代码不正确,它会输出一个错误,指示解释器无法解析我的代码。只有在我的代码正确的情况下,我
我正在使用ApacheSpark2.0并为DetaSet创建提及模式的DetaSet。当我试图根据定义自定义编码器时,对于java.time.LocalDate,我得到了以下异常:
java.lang.UnsupportedOperationException: No Encoder found for java.time.LocalDate
- field (class: "java.time.LocalDate", name: "callDate")
- root class: "FireService"
at org.apache.spar
我在scala中创建了注释,并按如下方式使用它: object Main extends App {
println(classOf[Annotated].getAnnotations.length)
import scala.reflect.runtime.universe._
val mirror = runtimeMirror(cls.getClassLoader)
}
final class TestAnnotation extends StaticAnnotation
@TestAnnotation
class Annotated 因为它是Scala注释,所以
我使用Scala宏并匹配Apply,我希望获得被调用的函数的完全限定名。
示例:
println("") -> scala.Predef.println
scala.Predef.println("") -> scala.Predef.println
class Abc {
def met(): Unit = ???
}
case class X {
def met(): Unit = ???
def abc(): Abc = ???
}
val a = new Abc()
val x = new Abc()
a.met() ->
我有一个特征T,我在C类中用宏实现它。我创建一个C的实例并调用它的方法。如果包含C实例的val的类型是C-则按预期工作。如果包含C实例的val的类型为T -调用方法,就如同T。 我能想到的最好的描述方式是scala-宏中的“虚拟表被打破”,但我不知道这是不是一件事…… 示例代码: Type in expressions for evaluation. Or try :help.
scala>
scala>
scala> import language.experimental.macros
import language.experimental.macros
sc
我正在编写一个创建Scala案例类的解析器生成器。举个例子:
case class Foo(
name : String,
age : Int
)(implicit other:Int){}
当我想要实现Foo实例时,我的解析器生成器了解所有3个成员,包括隐式的“other”。我有填充姓名和年龄的数据。
使用Scala反射,当创建对象以找到“other”的适当值时,我如何检查“隐式环境”?
我创建了一个Enumeration,如下所示:
scala> object J extends Enumeration {
| type J = Value
| val Fail, Success = Value
| }
defined object J
问题1-我试图创建一个变量的类型,但得到了以下错误。为什么?
scala> val j:J
<console>:11: error: not found: type J
val j:J
^
<console>:11: error: onl