获取Scala的/理解表达式的已废止部分? [英] Getting the desugared part of a Scala for/comprehension expression?
问题描述
有没有人知道在for/comprehension表达式实际尝试在REPL(或编译器)中进行编译之前,如何获得(仅限于Scala部分)经过简化的转换?
Does anyone know how to get the (Scala part only) desugared translation of a for/comprehension expression before it actually tries to compile in the REPL (or compiler)?
到目前为止,我唯一发现的是编译器的"-print"标志,但这为您提供了完整的Scala翻译……
The only thing I've found so far is the compiler "-print" flag but that gives you the full Scala translation…
推荐答案
似乎不存在直接在REPL中反糖化"for/comprehension"表达式的可能性.但是作为一种替代方案,可以使用一些Scala编译器选项,例如"-print"或简单表达式"Xprint:typer -e"
It doesn't seem to exists any possibilities to desugar "for/comprehension" expressions directly within the REPL. But as an alternative one can use some Scala compiler options like "-print" or for simple expressions "Xprint:typer -e"
示例:
要从文件中获取desugard输出,请使用"-print"标志:
To get the desugard output from a file use the "-print" flag:
# scala -print file.scala
要对简单的单线表达式进行糖化,请使用"-Xprint:typer -e"标志:
To desugar a simple one-liner expression, use the "-Xprint:typer -e" flag:
# scala -Xprint:typer -e "for (i <- 0 to 100) yield i"
这篇关于获取Scala的/理解表达式的已废止部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!