Question

I am finding that I use the scala repl more and more and I use it a lot when I don't have network. I have been adding my own functions to make discovery of apis easier (port over python's dir). One I am trying to do right now is get all functions added by implicits. I couldn't see a way to get this from scala reflection, so I thought I would take a look at the compiler to see how :implicits was created: https://github.com/scala/scala/blob/master/src/repl/scala/tools/nsc/interpreter/Imports.scala#L65.

Within the repl, is there any way to get access to the IMain instance? If not, is there another way to get a list of implicit methods (or all implicit conversion methods)?

I only care about getting these details within the repl, so if it wont work outside of the repl, that is fine.

Was it helpful?

Solution

FWIW, I'm making a couple of fixes for tab completion, and one suggested feature is to show enhancements after a couple of tabs.

scala> $intp
res0: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.ILoop$ILoopInterpreter@27fa135a

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> intp
res1: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.ILoop$ILoopInterpreter@27fa135a

scala> analyzer.allViewsFrom(IntTpe, typer.context, Nil)
res2: List[($r.intp.global.analyzer.SearchResult, List[$r.intp.global.analyzer.global.TypeConstraint])] = List((SearchResult(scala.this.Int.int2double, ),List()), (SearchResult(scala.this.Int.int2float, ),List()), (SearchResult(scala.this.Int.int2long, ),List()))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top