获取 Scala for/comprehension 表达式的脱糖部分? [英] Getting the desugared part of a Scala for/comprehension expression?
问题描述
有谁知道如何在真正尝试在 REPL(或编译器)中编译之前获得 for/comprehension 表达式的(仅限 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"
示例:
要从文件中获取脱糖输出,请使用-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 for/comprehension 表达式的脱糖部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!