1

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?

xhudik
  • 2,414
  • 1
  • 21
  • 39

2 Answers2

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.

Community
  • 1
  • 1
maxmc
  • 4,218
  • 1
  • 25
  • 21
  • thanks, i agree with the exception of: "Having tab autocompletion for r seems not really neccessary." - it is necessary when you are looking for possibilities (if you are not sure which function to use) – xhudik Mar 07 '13 at 09:30
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.

themel
  • 8,825
  • 2
  • 32
  • 31