Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result of scala.io.Source.fromFile(...).mkString(",") evaluation #6592

Closed
scabug opened this issue Oct 30, 2012 · 6 comments
Closed
Assignees
Labels

Comments

@scabug
Copy link

scabug commented Oct 30, 2012

I've 2 files that have only one difference - "\r\n" sequence in the test.txt
[vladimir@vladimir tmp]$ cat test.txt
line1
line2
line3
[vladimir@vladimir tmp]$ cat test2.txt
line1
line2
line3[vladimir@vladimir tmp]$

I try to execute in the REPL:

scala> scala.io.Source.fromFile("/tmp/test.txt").mkString(",")
res17: String =
,l,i,n,e,1,
,l,i,n,e,2,
,l,i,n,e,3,
"

scala> scala.io.Source.fromFile("/tmp/test2.txt").mkString(",")
res18: String =
,,i,n,e,1,
,l,i,n,e,2,
,l,i,n,e,3

scala>

As you can see, for test2.txt file the first "l" character ommited. I think, that it isn't expected behaviour.

@scabug
Copy link
Author

scabug commented Oct 30, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6592?orig=1
Reporter: Vladimir Kuptsov (vkuptcov)
Attachments:

  • test.txt (created on Oct 30, 2012 1:32:25 PM UTC, 21 bytes)
  • test2.txt (created on Oct 30, 2012 1:32:25 PM UTC, 19 bytes)

@scabug
Copy link
Author

scabug commented Oct 30, 2012

Alexei Tereschenko (aytereschenko) said (edited on Oct 30, 2012 1:47:35 PM UTC):
If I run the following code from an IDE, not from REPL:

object Test {
  def main(args: Array[String]) = {
    println(scala.io.Source.fromFile("/tmp/test.txt").mkString(","))
    println(scala.io.Source.fromFile("/tmp/test2.txt").mkString(","))
  }
}

then I receive the following output:

,
,
,l,i,n,e,3
,
,
,

@scabug
Copy link
Author

scabug commented May 20, 2013

@JamesIry said:
2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

1 similar comment
@scabug
Copy link
Author

scabug commented May 20, 2013

@JamesIry said:
2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

@scabug
Copy link
Author

scabug commented May 19, 2014

@som-snytt said:
This is as expected, or to be expected, or, as the doctors say, as well as could be expected.

The "\r," sequence places a comma in the first column of the terminal.

The difference between the two strings is that one ends in whitespace, so REPL displays it in quotes; the open quote is overstruck instead of the first char of text.

scala> scala.io.Source.fromFile("test2.txt").mkString(",") map { case '\r' => '*' case c => c }
res0: String =
l,i,n,e,1,*,
,l,i,n,e,2,*,
,l,i,n,e,3

scala> "a b c"
res1: String = a b c

scala> "a b c "
res2: String = "a b c "

@som-snytt
Copy link

It looks like CR echo progressed in 2.13 because of jline upgrade?

➜  ~/scala-2.12.9/bin/scala -Dscala.repl.info      
Welcome to Scala 2.12.9 (OpenJDK 64-Bit Server VM, Java 11.0.5).
Type in expressions for evaluation. Or try :help.
[info] started at Tue May 26 15:38:58 PDT 2020

scala 2.12.9> "abc\rxyz\n"
res0: String =
xyzc
"

scala 2.12.9> :quit
➜  scala -Dscala.repl.info 
[info] started at Tue May 26 15:39:16 PDT 2020
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 11.0.5).
Type in expressions for evaluation. Or try :help.

scala 2.13.2> "abc\rxyz\n"
val res0: String =
"abc
xyz
"

scala 2.13.2> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants