scala.Predef中$ scope的目的是什么?

soc*_*soc 6 xml scope scala library-design

scala.Predef 包含以下代码:

// Apparently needed for the xml library
val $scope = scala.xml.TopScope
Run Code Online (Sandbox Code Playgroud)

有人想出为什么它是必要的,考虑到它创建了可能很容易从标准库中分离出来的包的依赖关系?

ret*_*nym 4

看一下src/compiler/scala/tools/nsc/ast/parser/SymbolicXMLBuilder.scala, 以及解析 XML 文本的结果。

scala -Xprint:parser -e '<node/>'

new _root_.scala.xml.Elem(null, "node", _root_.scala.xml.Null, $scope)
Run Code Online (Sandbox Code Playgroud)

理想情况下,这将被移动到以下某个位置scala.xml;尝试一下,看看有什么问题。