This page is no longer maintained — Please continue to the home page at

Binding a value into the interpreter

No replies
Rodrigo Cano
Joined: 2009-03-22,
User offline. Last seen 42 years 45 weeks ago.
He there,
I'm having trouble binding a function into the interpreter, like this:

[rcano@scrat ~]$ scalaWelcome to Scala version (Java HotSpot(TM) Client VM, Java 1.7.0). Type in expressions to have them evaluated.Type :help for more information.
scala> :power** Power User mode enabled - BEEP BOOP SPIZ **** :phase has been set to 'typer'.          ** ** has been imported      **** global._ and definitions._ also imported **** Try  :help,  vals.<tab>,  power.<tab>    **
scala> power.repl.intp res0: =$ILoopInterpreter@19875b1
scala> val exampleFunction = (i: Int) => println("hell" + "o"*i) exampleFunction: Int => Unit = <function1>
scala> res0.bindValue("f", exampleFunction)<console>:5: error: object $read$ is not a member of package $line25   var value: .anonfun$1 = _                     ^<console>:6: error: object $read$ is not a member of package $line25  def set(x: Any) = value = x.asInstanceOf[.anonfun$1]

I know there is a bind which takes a manifest, but my code must interact with a Map[String, Object] (you know, the javax.script api, I know it sucks, but it allows me to have many different scripting engines, and ideally, I'll make some kind of scripting engine using scala) so it would be nice if the interpreter could realize that the class is an anonymous one, and extract its "public type".
Any ideas?

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland