scala-reflect

Dynamic compilation of multiple Scala classes at runtime

依然范特西╮ 提交于 2020-12-26 01:58:54
问题 I know I can compile individual "snippets" in Scala using the Toolbox like this: import scala.reflect.runtime.universe import scala.tools.reflect.ToolBox object Compiler { val tb = universe.runtimeMirror(getClass.getClassLoader).mkToolBox() def main(args: Array[String]): Unit = { tb.eval(tb.parse("""println("hello!")""")) } } Is there any way I can compile more than just "snippets", i.e., classes that refer to each other? Like this: import scala.reflect.runtime.universe import scala.tools

Dynamic compilation of multiple Scala classes at runtime

為{幸葍}努か 提交于 2020-12-26 01:57:27
问题 I know I can compile individual "snippets" in Scala using the Toolbox like this: import scala.reflect.runtime.universe import scala.tools.reflect.ToolBox object Compiler { val tb = universe.runtimeMirror(getClass.getClassLoader).mkToolBox() def main(args: Array[String]): Unit = { tb.eval(tb.parse("""println("hello!")""")) } } Is there any way I can compile more than just "snippets", i.e., classes that refer to each other? Like this: import scala.reflect.runtime.universe import scala.tools

Dynamic compilation of multiple Scala classes at runtime

醉酒当歌 提交于 2020-12-26 01:57:06
问题 I know I can compile individual "snippets" in Scala using the Toolbox like this: import scala.reflect.runtime.universe import scala.tools.reflect.ToolBox object Compiler { val tb = universe.runtimeMirror(getClass.getClassLoader).mkToolBox() def main(args: Array[String]): Unit = { tb.eval(tb.parse("""println("hello!")""")) } } Is there any way I can compile more than just "snippets", i.e., classes that refer to each other? Like this: import scala.reflect.runtime.universe import scala.tools

How to find class parameter datatype at runtime in scala

断了今生、忘了曾经 提交于 2020-12-15 05:26:12
问题 import scala.reflect.runtime.universe import scala.reflect.runtime.universe._ def getType[T: TypeTag](obj: T) = typeOf[T] case class Thing( val id: Int, var name: String ) val thing = Thing(1, "Apple") val dataType = getType(thing).decl(TermName("id")).asTerm.typeSignature dataType match { case t if t =:= typeOf[Int] => println("I am Int") case t if t =:= typeOf[String] => println("String, Do some stuff") case _ => println("Absurd") } Not able to digest why result is Absurd instead of I am

Why is a type of the member of the object different in a function?

廉价感情. 提交于 2020-12-04 10:19:49
问题 Code below produces following result: as member: nested: AnyRef{def x: Int; def x_=(x$1: Int): Unit} as local: nested: Object (Tested with Scala 2.12.12 and Scala 2.12.3) Can someone explain why? object Main extends App { def getNestedType(m: Any) = { import scala.reflect.runtime.currentMirror for { symbol <- currentMirror.classSymbol(m.getClass).toType.members if symbol.isTerm && !symbol.isMethod && !symbol.isModule } yield { s"{symbol.name.decodedName}: ${symbol.info}" } } object obj { var

Why is a type of the member of the object different in a function?

爱⌒轻易说出口 提交于 2020-12-04 10:18:27
问题 Code below produces following result: as member: nested: AnyRef{def x: Int; def x_=(x$1: Int): Unit} as local: nested: Object (Tested with Scala 2.12.12 and Scala 2.12.3) Can someone explain why? object Main extends App { def getNestedType(m: Any) = { import scala.reflect.runtime.currentMirror for { symbol <- currentMirror.classSymbol(m.getClass).toType.members if symbol.isTerm && !symbol.isMethod && !symbol.isModule } yield { s"{symbol.name.decodedName}: ${symbol.info}" } } object obj { var

Tensorflow in Scala reflection

回眸只為那壹抹淺笑 提交于 2020-11-29 19:36:22
问题 I am trying to get tensorflow for java to work on Scala. I am use the tensorflow java library without any wrapper for Scala. At sbt I have: If I run the HelloWord found here, it WORKS fine, with the Scala adaptations: import org.tensorflow.Graph import org.tensorflow.Session import org.tensorflow.Tensor import org.tensorflow.TensorFlow val g = new Graph() val value = "Hello from " + TensorFlow.version() val t = Tensor.create(value.getBytes("UTF-8")) // The Java API doesn't yet include

Tensorflow in Scala reflection

风格不统一 提交于 2020-11-29 19:30:55
问题 I am trying to get tensorflow for java to work on Scala. I am use the tensorflow java library without any wrapper for Scala. At sbt I have: If I run the HelloWord found here, it WORKS fine, with the Scala adaptations: import org.tensorflow.Graph import org.tensorflow.Session import org.tensorflow.Tensor import org.tensorflow.TensorFlow val g = new Graph() val value = "Hello from " + TensorFlow.version() val t = Tensor.create(value.getBytes("UTF-8")) // The Java API doesn't yet include

Tensorflow in Scala reflection

时光总嘲笑我的痴心妄想 提交于 2020-11-29 19:30:38
问题 I am trying to get tensorflow for java to work on Scala. I am use the tensorflow java library without any wrapper for Scala. At sbt I have: If I run the HelloWord found here, it WORKS fine, with the Scala adaptations: import org.tensorflow.Graph import org.tensorflow.Session import org.tensorflow.Tensor import org.tensorflow.TensorFlow val g = new Graph() val value = "Hello from " + TensorFlow.version() val t = Tensor.create(value.getBytes("UTF-8")) // The Java API doesn't yet include

Tensorflow in Scala reflection

喜你入骨 提交于 2020-11-29 19:29:13
问题 I am trying to get tensorflow for java to work on Scala. I am use the tensorflow java library without any wrapper for Scala. At sbt I have: If I run the HelloWord found here, it WORKS fine, with the Scala adaptations: import org.tensorflow.Graph import org.tensorflow.Session import org.tensorflow.Tensor import org.tensorflow.TensorFlow val g = new Graph() val value = "Hello from " + TensorFlow.version() val t = Tensor.create(value.getBytes("UTF-8")) // The Java API doesn't yet include