【问题标题】:In Scala's repl, programmatically find implicitly added functions在 Scala 的 repl 中,以编程方式查找隐式添加的函数
【发布时间】:2014-04-24 04:48:45
【问题描述】:

我发现我越来越多地使用 scala repl,而且当我没有网络时,我经常使用它。我一直在添加自己的函数以更轻松地发现 api(通过 python 目录移植)。我现在想做的一个是让所有函数都由隐式添加。我看不到从 scala 反射中得到这个的方法,所以我想我会看看编译器,看看 :implicits 是如何创建的:https://github.com/scala/scala/blob/master/src/repl/scala/tools/nsc/interpreter/Imports.scala#L65

在 repl 中,有什么方法可以访问 IMain 实例?如果没有,是否有另一种方法来获取隐式方法(或所有隐式转换方法)的列表?

我只关心在 repl 中获取这些详细信息,所以如果它在 repl 之外不起作用,那也没关系。

【问题讨论】:

    标签: scala read-eval-print-loop


    【解决方案1】:

    FWIW,我正在对选项卡完成进行一些修复,建议的一个功能是在几个选项卡之后显示增强功能。

    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()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 2012-04-03
      相关资源
      最近更新 更多