问题
if I write in scala 2.10 REPL (interactive Scala shell):
"""\w""".
And press TAB
it gives me:
+ asInstanceOf charAt
codePointAt codePointBefore
codePointCount compareTo compareToIgnoreCase
concat contains ....
However, .r
is missing. When I put the same string into eclipse, it offers me .r
as well. The same is true if I insert import scala.util.matching._
before.
Why REPL is not offering all possibilities?
Even bigger problem REPL has if i try to work with unicode, e.g. I write:
"""\p{L}""".
and press TAB
it gives me error:
scala> """\p{L}""".<console>:1: error: unclosed multi-line string literal
"""
^
Again, it works fine in Eclipse.
Is REPL so buggy, or am I missing something?
回答1:
The REPL only displays fields and methods of the object, while .r
is only available through an implicit conversion (augmentString
in scala.Predef) which turns it into a StringOps
. There is probably no reason for this besides the fact that it would need to be implemented and nobody got around to doing it. You can still call .r
on this, of course.
The Scala IDE is smart enough to resolve implicits, which is why you can see it there.
回答2:
Yes, r
is missing, but if you write """\w""".r
and press enter it nevertheless works res0: scala.util.matching.Regex = \w
. Having tab autocompletion for r
seems not really neccessary.
The unicode issue is probably caused by java. You can explicitly request UTF-8 if you pass -Dfile.encoding=UTF-8
to java. Here is a post which describes how to do it.
If you use Eclipse, I can reccommend the Scala worksheet plugin which is a very good repl replacement.
来源:https://stackoverflow.com/questions/15267235/scala-repl-fails-to-autocomplete-methods-that-comes-from-implicit-conversion